You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by "Chan, Philip" <Ph...@rbccm.com> on 2002/01/08 20:13:15 UTC

How to use XPathAPI.selectNodeIternator when namespace is used?

Hi,

Does anyone know how to use ApplyXPath.java example program (version 2.2
D14) to select a nodeIternator when namespace is used?

For example, given an XML named test.xml:
<?xml version="1.0" encoding="UTF-8"?>
<root>
   ...
</root>

This test.xml works fine with the ApplyXPath.java sample program.  We could
run it with the command:
java ApplyXPath test.xml /root
and will get everything as <output><root> ... </root></output>

However, if the namespace is used and declared as:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.xxx.com/ns" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.xxx.com/ns test.xsd">
   ...
</root>

The test.xml will not be able to extract the root nodeIternator and return
null.  The output of the ApplyXPath will then be
<output></output>

I understand that if I modify the program and set the NamespaceAware to
false, then the XPathApi.selectNodeIternator(doc, xpath) will return a
correct answer.

What should we do if we do need the
DocumentBuilderFactory.setNamespaceAware(true)?

Thanks
Philip