Does not support the expression : /descendant::node()/rec/child::node()[1]?

141 views
Skip to first unread message

Ming Chen

unread,
Jan 5, 2012, 9:14:09 PM1/5/12
to xpath...@googlegroups.com

Hi,

 

I have a XML file as follows:

 

<?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" />

      <para type="error" position="4" />

      <para type="warning" position="5" />

      <para type="error" position="6" />

    </rec>

    <rec id="2">

      <para type="warning" position="1" />

      <para type="warning" position="2" />

      <para type="warning" position="3" />

      <para type="warning" position="4" />

      <para type="warning" position="5" />

      <para type="warning" position="6" />

    </rec>

    <rec id="3">

      <para type="warning" position="1" />

      <para type="warning" position="2" />

      <para type="warning" position="3" />

      <para type="warning" position="4" />

      <para type="error" position="5" />

      <para type="warning" position="6" />

    </rec>

  </table>

</xml>

 

Then copied /descendant::node()/rec/child::node()[1] to the XPath text box. Then press the Test! Button. The XPathtester output:

 

<?xml version="1.0" encoding="UTF-8"?>

 

<root></root>

 

If I change the XPath expression to /descendant::node()/rec/child::*[1] or /descendant::node()/rec/para[1], the output would be:

 

<?xml version="1.0" encoding="UTF-8"?>

 

<root>

  <para type="error" position="1"/>

  <para type="warning" position="1"/>

  <para type="warning" position="1"/>

</root>

 

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.

 

Shouldn’t it have the same output as /descendant::node()/rec/child::*[1] or /descendant::node()/rec/para[1]?

 

 

Thanks,

Ming

Ming Chen

unread,
Jan 9, 2012, 11:45:04 PM1/9/12
to XPath Tester help center
Close this question because I have got the answer from the libxml
mailing list.

From: Liam R E Quin <li...@holoweb.net>
To: Ming Chen <cimin...@yahoo.com>
Cc: "x...@gnome.org" <x...@gnome.org>
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/
Reply all
Reply to author
Forward
0 new messages