XPath expression that gets a node with 2 particular children

XPath expression that gets a node with 2 particular children

Post by Jef » Mon, 07 Jul 2003 01:39:11



I'd like to write an XPath expression that gets a node with 2
particular children.

I thought this would work:
/AAA/BBB/CCC/following-silbing::DDD/parent::node()

on xml like this:

AAA
  BBB
    CCC
    DDD
  /BBB
/AAA

But it doesn;t seem to.  I've been testing it here:
http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html
I would like to have some sort of "/sibling::DDD" so that I can find
any sib not just following or preceeding, but I can't seem to find a
way to do that either.

Any ideas?

BTW, My next step is to also require the that a particular attribute
of one of the children has one of a set of values.

Thanks.

 
 
 

XPath expression that gets a node with 2 particular children

Post by Dimitre Novatche » Mon, 07 Jul 2003 03:00:52


Quote:> AAA
>   BBB
>     CCC
>     DDD
>   /BBB
> /AAA

This is not xml at all, probably you meant:

<AAA>
  <BBB>
    <CCC/>
    <DDD/>
  </BBB>
</AAA>

Use:

   /AAA/BBB[CCC and DDD and not(*[3])]

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


Quote:> I'd like to write an XPath expression that gets a node with 2
> particular children.

> I thought this would work:
> /AAA/BBB/CCC/following-silbing::DDD/parent::node()

> on xml like this:

> AAA
>   BBB
>     CCC
>     DDD
>   /BBB
> /AAA

> But it doesn;t seem to.  I've been testing it here:
> http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html
> I would like to have some sort of "/sibling::DDD" so that I can find
> any sib not just following or preceeding, but I can't seem to find a
> way to do that either.

> Any ideas?

> BTW, My next step is to also require the that a particular attribute
> of one of the children has one of a set of values.

> Thanks.


 
 
 

XPath expression that gets a node with 2 particular children

Post by Dimitre Novatche » Mon, 07 Jul 2003 03:20:53


In case the order of the children matters, then this should be reflected in
the XPath expression:

/AAA/BBB[ *[1][self::CCC] and *[2][self::DDD] and not(*[3])  ]

=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL


> > AAA
> >   BBB
> >     CCC
> >     DDD
> >   /BBB
> > /AAA

> This is not xml at all, probably you meant:

> <AAA>
>   <BBB>
>     <CCC/>
>     <DDD/>
>   </BBB>
> </AAA>

> Use:

>    /AAA/BBB[CCC and DDD and not(*[3])]

> =====
> Cheers,

> Dimitre Novatchev.
> http://fxsl.sourceforge.net/ -- the home of FXSL



> > I'd like to write an XPath expression that gets a node with 2
> > particular children.

> > I thought this would work:
> > /AAA/BBB/CCC/following-silbing::DDD/parent::node()

> > on xml like this:

> > AAA
> >   BBB
> >     CCC
> >     DDD
> >   /BBB
> > /AAA

> > But it doesn;t seem to.  I've been testing it here:
> > http://www.zvon.org:9001/saxon/cgi-bin/XLab/XML/source1.html
> > I would like to have some sort of "/sibling::DDD" so that I can find
> > any sib not just following or preceeding, but I can't seem to find a
> > way to do that either.

> > Any ideas?

> > BTW, My next step is to also require the that a particular attribute
> > of one of the children has one of a set of values.

> > Thanks.

 
 
 

1. Getting the result of an XPath Expression that doesn't return a node

Hi All.

Is there a way to get the value of an XPath Expression that doesn't retun a
node.  This is the code I'm using:

    Dim o As New MSXML2.DOMDocument30
    o.setProperty "SelectionLanguage", "XPath"
    o.loadXML "<root><a>1</a><a>3</a><a>2</a></root>"
    o.selectSingleNode ("sum(//a)")

When I run it, I get this error (which makes sense):
"Expression doesn't return a DOM node"

However, I can't find any method on the DOM interface that will let me
execute an XPath expression and get the result as a string.

Any help would be greatly appreciated.

Thanks.

/Scott

2. Antimony's Mizer and FrontPage

3. Problem getting node children and text without the node tag

4. Lame nameservers, what to do

5. Is there an XPath expression to get an element and a subset of its children?

6. How to connect a raw socket to a server using TCP/IP

7. XPATH: Select parent node when child node attribute is known

8. What MacOS Colorsync to use for SGI 1600SW?

9. Child Nodes's Child Node creation

10. why am I getting the child node value?

11. Getting Nodes without the childs

12. Getting the number of children for a node.

13. Union expressions ( | symbol) allowed in schema selector XPATH expressions?