Re: [xml] XPath evaluation



=?ISO-8859-1?Q?Fabrice_Desr=E9_-_France_Telecom_R=26D/MAP?=
=?ISO-8859-1?Q?S/AMS?= <fabrice desre francetelecom com> writes:

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>

prefixes without declerations are ok though arn't they? I thought that
was one of the design ideas behind namespaces; that colon separated
node names are just names.


Nic



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