2

I'm struggling to get the value of an XML node using the FilterXML() function when the XML document's document element has a namespace specified.

Example:

<?xml version="1.0" encoding="UTF-8"?>
<DocumentElement xmlns="XMLSchemaDefinition.xsd">
    <Field>
        <Value>100</Value>
    </Field>
</DocumentElement>
= FILTERXML(A1, "/Document/Element/Value[1]")


I managed to get FilterXML working by removing the namespace in the following manner:

= FILTERXML(SUBSTITUTE(A1, "<DocumentElement xmlns=""XMLSchemaDefinition.xsd"">", "<DocumentElement>"), "/DocumentElement/Field/Value[1]")


Is there a way to get the value of the XML node without having to remove the namespace(s)?

I'm currently using LibreOffice Version: 5.0.5.2

2
  • In <?xml version=""1.0"" encoding=""UTF-8""?> the quotes should be " instead of "".
    – Jim K
    Mar 5, 2016 at 2:50
  • @jim-k Thank you for pointing that out. I've fixed the error. Mar 5, 2016 at 4:20

1 Answer 1

0

Ignore the namespace like this:

= FILTERXML(A1, "/*[name()='DocumentElement']/*[name()='Field']/*[name()='Value'][1]")

See https://stackoverflow.com/questions/5239685/xml-namespace-breaking-my-xpath.

1
  • Thank for the link to "XML namespace breaking my XPath". I didn't know namespaces could/would create such issues. Mar 5, 2016 at 4:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .