Skip to Content.
Sympa Menu

xom-interest - Re: [XOM-interest] Namespaces and attributes

xom-interest AT lists.ibiblio.org

Subject: XOM API for Processing XML with Java

List archive

Chronological Thread  
  • From: Elliotte Rusty Harold <elharo AT metalab.unc.edu>
  • To: Mik Lernout <mik AT futurestreet.org>
  • Cc: xom-interest AT lists.ibiblio.org
  • Subject: Re: [XOM-interest] Namespaces and attributes
  • Date: Tue, 25 Nov 2003 18:02:33 -0500

At 11:22 PM +0100 11/25/03, Mik Lernout wrote:

String xmlAsString = "<test xmlns:test=\"http://test.org/Test\";><a test:attribute=\"attributeValue\"></a></test>";
Builder parser = new Builder();
Document doc = null;
try{
doc = parser.build(new StringReader(xmlAsString));
Element aElement = doc.getRootElement().getFirstChildElement("a");
System.out.println("Found attribute value of: " + aElement.getAttributeValue("http://test.org/Test","attribute";))

In XOM, the name always comes before the URL. Flip the order of your arguments, that is:

aElement.getAttributeValue("attribute", "http://test.org/Test";)

Hmmm, I wonder if there's an inexpensive way I could test this on getAttributevalue (and many similar calls) to warn the user what they're doing wrong at least some of the time. If this were a constructor, then there would be an exception here, but even there perhaps the exception could be clearer?
--

Elliotte Rusty Harold
elharo AT metalab.unc.edu
Effective XML (Addison-Wesley, 2003)
http://www.cafeconleche.org/books/effectivexml
http://www.amazon.com/exec/obidos/ISBN%3D0321150406/ref%3Dnosim/cafeaulaitA




Archive powered by MHonArc 2.6.24.

Top of Page