Hi,
Was wondering why dom4j doesn't appear to allow
namespace processing to be turned off i.e setting the parser feature http://xml.org/sax/features/namespaces to
false.
So how do I parse the following XML
<a>
<ns:b>content</ns:b>
</a>
without getting the prefix ns is not bound fatal
error?
Using JAXP I can parse the above without errors by
setting the flag on the factory
SAXParserFactory spf =
SAXParserFactory.newInstance();
spf.setNamespaceAware(true); or with SAX itself I can set the feature on the
XMLReader
xmlReader.setFeature("http://xml.org/sax/features/namespaces",false);
However in dom4j neither of these turned off
namespace processing:
SAXReader saxReader = new SAXReader();
saxReader.setFeature("http://xml.org/sax/features/namespaces",false);
or
saxReader.getXMLReader().setFeature("http://xml.org/sax/features/namespaces",false);
Looking at the source of SAXReader it appears that
this feature is hard coded in configureReader: SAXHelper.setParserFeature(reader, "http://xml.org/sax/features/namespaces",
true)
As a work around you can load a W3C Dom and
then hand it over to dom4j using DOMReader but it would be better if users only
have to deal with one model.
Does this mean that dom4j can only be used in a
namespace aware fashion? Was this for some reason a concious design decision?
Would be useful if there was a setNamespaceAware method on SAXReader (similar to
the exisiting setValidation).
My apologies if this has been discussed before, but
couldn't find anything on this in the archives.
Thanks,
Karl.
Karl Nesbitt
Cladonia.
|