Re: [xml] XPath evaluation



CAPRON Patrick wrote:
I have tried with the use of xmlXPathRegisterNs, but it doesn't work.
xmlXPathRegisterNs(xpathCtx, BAD_CAST "urn:ssp.ApplicationHeader$ahV10", BAD_CAST "")
xmlXPathRegisterNs(xpathCtx, BAD_CAST "urn:ssp.pm.GetAccount$camt.003.001.02", BAD_CAST "")
xmlXPathRegisterNs(xpathCtx, BAD_CAST "SwInt", BAD_CAST "")

It has the same behaviour...
/REQUEST/RequestPayload/Document doesn't work
/REQUEST/RequestPayload/*[name()='Document'] works fine

The second query works because 'Document' is the name if the element... If you use local-name() instead it wont work anymore.

You're facing a faq about XPath and default namespaces : there is no default namespace in XPath. So if you want to select a namespaced element, you must bind the namespace's uri to a prefix and use it in your xpath expression. It doesn't matter if your document is using a default namespace or a prefix.

So try something like : xmlXPathRegisterNs(xpathCtx, BAD_CAST "urn:ssp.pm.GetAccount$camt.003.001.02", BAD_CAST "ssp");
and the query : /REQUEST/RequestPayload/ssp:Document

And also, your document uses a prefix that is not declared :
t.xml:10: namespace error : Namespace prefix SwInt on RequestPayload is not defined
     <SwInt:RequestPayload>

        Fabrice
--
Fabrice Desré
France Télécom R&D/MAPS/AMS
Tél: +(33) (0)2 96 05 31 43
Fax: +(33) (0)2 96 05 39 45
http://www.francetelecom.com/rd



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]