0

I have an an xpath

//ServiceDefinition/schema/sequenceType[@name="Data"]/element/@name')) 

That works great with xml

<ServiceDefinition>
   <schema>
      .....
   </schema>
</ServiceDefintion>

The issue is the first line of xml file really is

  <ServiceDefinition xmlns="http:/schemas/api" name="thename" version="1.0.0.45">

The above xpath returns empty when I include those 3 attributes. Is there a way to modify the xpath so look for this ServiceDefinition element but does not care about the attributes? I know I can specify values for the 3 attributes but at least the version will change. I know I can wildcard the values but could not figure a way to just inspect the attributes at all

Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
personalt
  • 810
  • 3
  • 13
  • 26
  • I think you are right.. Is this effectivly saying that reason for no match is not that I have those xml attributes but that one is specifically one that defines the name space? – personalt Nov 15 '17 at 21:23
  • Yes, it's specifically the `xmlns` attribute that is bugging you. Any other attribute is fine. – Ruud Helderman Nov 15 '17 at 21:30
  • You can either register the namespace (method depends on hosting language) or you can bypass them (not recommended). See [*my answer to How does XPath deal with XML namespaces?*](https://stackoverflow.com/a/40796315/290085) for a thorough explanation of your options either way (for many different hosting languages too). – kjhughes Nov 15 '17 at 21:41
  • if you are using DOM, just turn off namespace awreness... not hard at all... – vtd-xml-author Nov 15 '17 at 22:57
  • I did this to support the namespace `my $filename = '/home/myfile.xml'; my $dom = XML::LibXML->load_xml(location => $filename);` my $xpc = XML::LibXML::XPathContext->new($dom); $xpc->registerNs('ns', 'http://schemas/apidd'); foreach my $title ($xpc->findnodes('//ns:ServiceDefinition/schema')) { say $title->to_literal(); }; What is weird is my xpath is behaving a bit different ns:ServiceDefinitionn returns data but when I start to build out the xpath further it fails. does using the name space return additional changes to the xpath? – personalt Nov 15 '17 at 23:01
  • If I wanted to turn off namespace awareness, how does one do that? @vtd-xml-author – personalt Nov 15 '17 at 23:06
  • I was able to address the above smaller issue be adjusting findnodes to have ns in front of each node. – personalt Nov 16 '17 at 12:56

0 Answers0