xom-interest AT lists.ibiblio.org
Subject: XOM API for Processing XML with Java
List archive
- 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
-
[XOM-interest] Namespaces and attributes,
Mik Lernout, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
Elliotte Rusty Harold, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
Nils_Kilden-Pedersen, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
John Cowan, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
Elliotte Rusty Harold, 11/25/2003
- Re: [XOM-interest] Namespaces and attributes, Nils_Kilden-Pedersen, 11/26/2003
-
Re: [XOM-interest] Namespaces and attributes,
Elliotte Rusty Harold, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
John Cowan, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
Nils_Kilden-Pedersen, 11/25/2003
-
Re: [XOM-interest] Namespaces and attributes,
Elliotte Rusty Harold, 11/25/2003
Archive powered by MHonArc 2.6.24.