0

I have an XML document with the following structure:

<?xml version="1.0" encoding="utf-8"?>
  <ooh>
    <occupation>
      <title type="text">Accountants and Auditors</title>
    </occupation>
    <occupation>
      <title type="text">Another Title</title>
    </occupation>
  </ooh>

What do I enter in the QueryPath XML Parser to set the context to be Occupation and add the title as a new source? I tried //ooh//occupation but I keep getting this error: CSS selector is not well formed.

enter image description here

2
  • Are you sure that error isn't "XML is not well formed" ? Your XML is invalid at the moment is all. Your query is valid, but if you want to extract the title it'll be something more like //ooh/occupation/title/text()
    – Clive
    Commented Dec 8, 2015 at 21:57
  • I had simplified the XML a little for this post, but I tried an XML validator and didn't get any errors. I updated the XML above to better reflect the actual XML. And I agree that "XML is not well formed" would be a sensible error, but it is specifying 'CSS selector is not well formed.' Commented Dec 9, 2015 at 14:43

1 Answer 1

1

The context should be the outer most wrapper of each item, so if your XML is

<ooh>
  <occupation>
   <title>Some Title</title
  </occupation>
</ooh>
<ooh>
  <occupation>
   <title>Another Title</title
  </occupation>
</ooh>

The context would be //ooh and the children of 'ooh' would be entered as occupation and occupation/title.

If occupation is the outermost wrapper of each item like:

<ooh>
  <occupation>
   <title>Some Title</title
  </occupation>
  <occupation>
   <title>Another Title</title
  </occupation>
</ooh>

The context would be //occupation and the title would be entered as title

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.