in reply to xmlns and XML::LibXML

see xpather.pl , it will spit out stuff like this, you only need to match on local-name() (just delete the other "and" conditions )

xpath1

# star /*[ local-name() = "propfind" and namespace-uri() = "DAV:" and position() = 1 ] /*[ local-name() = "prop" and namespace-uri() = "DAV:" and position() = 1 ] /*[ local-name() = "bigbox" and namespace-uri() = "http://ns.example.com/boxschema/" ]

xpath2

/*[ local-name() = "propfind" and namespace-uri() = "DAV:" and position() = 1 ] /*[ local-name() = "propname" and namespace-uri() = "DAV:" ]

see xpather.pl , Re: XML::LibXSLT ignoring namespace on some Win32 machines (libxslt-1.1.27 bug), Re^5: Xpath not working, Re^8: How to parse xml with namespase vale in XMl:LibXML? (autoRegisterNs ), Re: XML::LibXML and namespaces, Re^2: Namespaced XML::LibXML XPath query (not a bug)

The XML FIles: Understanding XML Namespaces, Re: XML::LibXSLT ignoring namespace on some Win32 machines (libxslt-1.1.27 bug), Re^2: XML::LibXML and namespaces, Re^2: XML::LibXML and namespaces, Re: XML::LibXML and namespaces, XPATH DOM traverse html/xml,

Replies are listed 'Best First'.
Re^2: xmlns and XML::LibXML ( local-name() )
by Anonymous Monk on Jun 02, 2015 at 03:18 UTC
    you only need to match on local-name()

    ... which would make code non-namespace-aware and doesn't answer the question "how I am supposed to make XML::LibXML correctly use name spaces" (the answer recommended by XML::LibXML is XML::LibXML::XPathContext). The whole topic has been discussed before, actually in the thread you linked to: Xpath not working.

      ..which would make code non-namespace-aware and doesn't answer the question...The whole topic has been discussed before, actually in the thread you linked to..

      Hmm, I wonder why I linked that threat, its almost like I want folks to read it and make up their own minds

        I have read all the threads I can find. (Different from understanding them all perhaps) and I have not found the answer

        I have been using XML examples from the RFC4918, but the two namespace cases are different in other ways too. So I will construct an example

        Is it true that:

        <?xml version="1.0" encoding="utf-8" ?> <propfind xmlns="DAV:"> <propname/> </propfind>

        and

        <?xml version="1.0" encoding="utf-8" ?> <D:propfind xmlns:D="DAV:"> <D:propname/> </D:propfind>

        are the same (semantically)?

        If so then the same Perl code should parse them, if not I am more confused than I thought

        Worik

        Update: The same Perl code and Xpath