In it I register 'D' as a prefix for 'DAV:' and so using a XPath with 'D' as prefix works where the XML uses it too.

No, the expression /D:propfind/D:propname works on both $txt1 and $txt2.

Your sub testfn does not give you enough information. If $dom->findnodes($xpath) blows up, the second "test case" $xc->findnodes($xpath) never gets executed.

/DAV:propfind/DAV:propname will not work because you have not registered a prefix "DAV" with the XPathContext.

/propfind/propname will not work because that expression seeks nodes without a namespace, but the nodes in your document have a namespace.

$dom->findnodes($xpath) will not always work because it lacks the power that XPathContext provides.

Please also reference your previous thread xmlns and XML::LibXML, a lot has already been discussed there.

There is further documentation in XML::LibXML::Node under findnodes, in XML::LibXML::XPathContext, and actually plenty of good information on the net in general: xpath namespace.


In reply to Re: Using XPaths with XML::LibXML and XPathContext by Anonymous Monk
in thread Using XPaths with XML::LibXML and XPathContext by worik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.