1

This XPath statement looks valid to me.

/wsdl:definitions/wsdl:types/xsd:schema/xsd:element[@name='GetBook']//*[@name='ID']/@type

And indeed if I use it in this online parser http://xpather.com/ it works like a champ

I am using libxml2 on alpine linux compiling with gcc

Here is my XPath line :

const char* xpath = "/wsdl:definitions/wsdl:types/xsd:schema/xsd:element[@name='GetBook']//*[@name='ID']/@type";

and here is where I got the demo WSDL from https://tomd.xyz/wsdl/

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • Does this answer your question? [LibXML doesn't find any nodes for my xpath expression](https://stackoverflow.com/questions/3830553/libxml-doesnt-find-any-nodes-for-my-xpath-expression) – nwellnhof Oct 29 '20 at 16:31

1 Answers1

1

XML namespace prefixes such as wsdl and xsd must be bound to XML namespaces, and the method of declaring such a binding is implementation-dependent. If your XPath is working without explicitly defining the namespace prefixes, it is possible that the tool has automatically ascertained the correct binding of namespace prefix with namespaces via inspection of the XML document. There is no obligation on the part of the XPath tool/library to do so, and you should not expect it.

See also How does XPath deal with XML namespaces?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
  • I added the namespaces already. My question is why does this XPath not work. – Charlie Benger-Stevenson Oct 24 '20 at 19:32
  • 1
    Where and how did you add namespace prefix declarations? You've shown nothing of the sort. You've also not shown your XML or code in your question. Until you provide a [mcve], state the actual results and how they differ from your desired results, you've not provided sufficient information to help you further. – kjhughes Oct 24 '20 at 20:25