From: Ming C. <cim...@ya...> - 2012-01-10 05:05:50
|
Hi Noam, Recently I get different outputs with those tools: XmlStar, XPathBuilder, XmlLint (win32 version, with libxml2 underneath) and XPathTester (online tool), for below XML file: <?xml version="1.0" encoding="UTF-8"?> <xml> <table> <rec id="1"> <para type="error" position="1"/> <para type="error" position="2"/> <para type="error" position="3"/> </rec> <rec id="2"> <para type="warning" position="1"/> <para type="warning" position="2"/> <para type="warning" position="3"/> </rec> <rec id="3"> <para type="info" position="1"/> <para type="info" position="2"/> <para type="info" position="3"/> </rec> </table> </xml> While my original expected outputs (which really is XmlStar and XPathBuilder's output) are: "<para type="error" position="1"/><para type="warning" position="1"/><para type="info" position="1"/>", the XmlLint and XPathTester give some empty lines actually. I asked this question to the libxml2 mailing list, and got below answers: From: Liam R E Quin <li...@ho...> To: Ming Chen <cim...@ya...> Cc: "xm...@gn..." <xm...@gn...> Sent: Tuesday, January 10, 2012 11:22 AM Subject: Re: [xml] Does not support the expression : /descendant::node()/rec/child::node()[1]? On Mon, 2012-01-09 at 18:54 -0800, Ming Chen wrote: > According to the XPath spec (V2.0 section 3.2.3 Unabbreviated > Syntax) : child::node() selects all the children of the context node. Note > that no attribute nodes are returned, because attributes are not > children. Note, libxml2 actually only supports XPath 1, not XPath 2. However, /descendant::node()/rec/child::node()[1] will match text nodes, and you're getting the blank (whitespace-only) text node that's the first child of elements, since your input is "indented". > Shouldn’t it have the same output as > /descendant::node()/rec/child::*[1] and /descendant::node()/rec/para[1]? No. The first child node in <rec id="1"> <para type="error" position="1"/> is the newline and spaces between id="1"> and <para. Liam -- Liam Quin - XML Activity Lead, W3C, http://www.w3.org/People/Quin/ Pictures from old books: http://fromoldbooks.org/ I think that explanation is legal. What's your opinion on this? Thanks, Ming |