I have a simple program to run xpath with xerces 1_2_7
XPathFactory factory = XPathFactory.ne wInstance();
XPath xPath = factory.newXPat h();
XPathExpression xp = xPath.compile(s trXpr);
System.out.prin tln(xp.evaluate (new InputSource(new
FileInputStream ("a.xml")))) ;
if a.xml is
<?xml
version="1.0"?> <root><parent>< son>theTextValu e</son></parent></root>
and strXpr is /root/parent/son/text()
I got correct value back "theTextVal ue".
But if parent is with namespace, such as soap message, it always fails,
eg.:<?xml version="1.0"?> <soap:Envelop e
xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"><soap :Body><son>theV alue</son>
</soap:Body></soapEnvelope>
strXpr is /soap:Envelope/soap:Body/son/text()
empty string was returned...
Any suggestion are welcome.
Thanks.
XPathFactory factory = XPathFactory.ne wInstance();
XPath xPath = factory.newXPat h();
XPathExpression xp = xPath.compile(s trXpr);
System.out.prin tln(xp.evaluate (new InputSource(new
FileInputStream ("a.xml")))) ;
if a.xml is
<?xml
version="1.0"?> <root><parent>< son>theTextValu e</son></parent></root>
and strXpr is /root/parent/son/text()
I got correct value back "theTextVal ue".
But if parent is with namespace, such as soap message, it always fails,
eg.:<?xml version="1.0"?> <soap:Envelop e
xmlns:soap="htt p://schemas.xmlsoap .org/soap/envelope/"
xmlns:xsd="http ://www.w3.org/2001/XMLSchema"
xmlns:xsi="http ://www.w3.org/2001/XMLSchema-instance"><soap :Body><son>theV alue</son>
</soap:Body></soapEnvelope>
strXpr is /soap:Envelope/soap:Body/son/text()
empty string was returned...
Any suggestion are welcome.
Thanks.
Comment