1

I am using xmlsec to parse an xml to generate xml signature. And after reading wikipedia page on XPath, I tried to sign following sample xml file.

My xml looks like this:

<References>
    <env:Envelope>
        <book:Book xml:id="BookBSchneier">
                <tns:search>
                </tns:search>
                <audit:user >
                </audit:user>
        </book:Book>
  </env:Envelope>
</References>

I have given xpath like this:

/child::References/child::env:Envelope/child::book:Book/child::audit:user

But it is giving error:

XPath error : Undefined namespace prefix XPath error : Invalid expression

Arjun Chaudhary
  • 2,373
  • 2
  • 19
  • 36
  • 2
    If you use a namespace-prefix in an XPath expression, you must define what namespace to bind to the prefix and register it with the engine executing the XPath. What are the namespace for the `env`, `book`, and `audit` namespace-prefixes? Your example XML is not valid. Those elements don't have namespaces for those prefixes either. – Mads Hansen Apr 11 '18 at 01:28
  • 1
    First make your XML [***namespace-well-formed***](https://stackoverflow.com/a/25830482/290085) by declaring the namespace prefixes in use, as @MadsHansen recommends. Then see the duplicate link for [**how to use XPath with namespaces**](https://stackoverflow.com/q/40796231/290085). – kjhughes Apr 11 '18 at 01:49

0 Answers0