1

I'm trying to find a nice solution to search in xml-documents by using XPath. The problem I'm facing are the different xml-documents I'm receiving. Some of them use namespaces and others don't but they all have the same structure.

What I've done so far: I registered a namespace a: with the received namespace and all of my queries look like xpath('a:query') but when a document without namespace is being received I don't know what to register a: with because I don't want to create two different xpath-queries (one with and one without namespace).

Stackoverflow has a lot about ignoring the namespace completely but this is not a nice option. What other options are possible?

Thanks a lot.

Nino
  • 402
  • 3
  • 8
  • try to define the prefix (`a` in your example above) to point to empty uri in the case when you have XML without namespace. With that you can use the same XPath for both XML type (with and without namespace). – har07 Apr 05 '14 at 09:51
  • Thanks. I'm using SimpleXML and when I call registerXPathNamespace('a', '') XPath cannot find any elements. Did you mean this by "empty uri"? – Nino Apr 05 '14 at 09:59
  • yes, that's what I mean, empty uri means empty string. Worked for me in .NET, unfortunately doesn't seems good for you with SimpleXML – har07 Apr 05 '14 at 10:09
  • possible duplicate of [How can I get JDOM/XPath to ignore namespaces?](http://stackoverflow.com/questions/2607432/how-can-i-get-jdom-xpath-to-ignore-namespaces) – akostadinov Aug 17 '15 at 13:27

0 Answers0