[Home] [By Thread] [By Date] [Recent Entries]

  • From: Michael Sokolov <sokolov@i...>
  • To: xml-dev@l...
  • Date: Wed, 17 Nov 2010 21:25:42 -0500

On 11/17/2010 1:35 PM, Martin Honnen wrote:
>
> I think the Java DOM APIs can handle that:
>
>       DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
>       DocumentBuilder db = dbf.newDocumentBuilder();
>       Document doc = db.parse(new InputSource(
> new StringReader("<related-article xlink:href=\"xxx\" />")));
>
> System.out.println(doc.getDocumentElement().getAttribute("xlink:href"));
>

That's interesting: I was attempting to parse using Xerces as a SAX 
parser and I got an error:

2010-11-17 11:41:19,855 ERROR org.xml.sax.SAXParseException: The prefix 
"xlink" for attribute "xlink:href" associated with an element type 
"related-article" is not bound.

Perhaps this was due to having passed the SAX Source to an xslt 
transformer (saxon).  I suppose it's possible saxon changed the 
namespace-awareness after I had already set it?  Anyway, it sounds like 
this whole course of action may be dubious and my only recourse is to 
tell the client: add declarations to your xml, or perhaps to fix it 
myself by wrapping an outer element with the missing decls.

However, although the question seems to be purely academic at this 
point, I'm still wondering why there is an option for 
namespace-aware=false.  Perhaps at some point in the past there was an 
idea of backwards compatibility that is no longer relevant?

-Mike


[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index]


Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member