This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Microsoft XML > February 2005 > Returning Nodes which have 2 or more Child Nodes
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Returning Nodes which have 2 or more Child Nodes
|
|
| Jerry West 2005-02-22, 11:21 pm |
| <Test>
<Order id="1">
<Key/>
<Key/>
</Order>
<Order id="2">
<Key>
</Order>
</Test>
I want to return any Nodes which have two or more Child Nodes. For example,
in the above XML fragment I want to return all of the Order Nodes which have
two or more Key Nodes. How does one do that?
JW
| |
| Bjoern Hoehrmann 2005-02-23, 4:29 am |
| * Jerry West wrote in microsoft.public.xml:
><Test>
> <Order id="1">
> <Key/>
> <Key/>
> </Order>
> <Order id="2">
> <Key>
> </Order>
></Test>
>
>I want to return any Nodes which have two or more Child Nodes. For example,
>in the above XML fragment I want to return all of the Order Nodes which have
>two or more Key Nodes. How does one do that?
I am not sure what you mean by "return" in this context, but you can
select them using XPath, this would be
//node()[count(node()) >= 2]
Or if you mean elements rather than nodes
//*[count(*) >= 2]
See the MSDN documentation on how to use XPath in your application.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
| |
| Jerry West 2005-02-23, 4:29 am |
| Thank you for the reply. I tried the 1st example below but this always
returns an error that states "Unknown Method". The error indicates the
unknown method is: -->count(node<--
I tried changing the statement various ways thinking that the word "node"
should be changed to reflect the Node name in the XML fragment I showed. For
example:
//node()[count(Key()) >= 2]
//Order/()[count(Key()) >= 2]
//node()[count(node(Key)) >= 2]
Everything I tried yields errors. When I looked up the node() statement on
MSDN it always talks about Nodes versus a function. Is the node() statement
in your example a function or the string I should change to match my XML
example?
JW
"Bjoern Hoehrmann" <bjoern@hoehrmann.de> wrote in message
news:424b1b31.244449546@news.bjoern.hoehrmann.de...
>* Jerry West wrote in microsoft.public.xml:
>
> I am not sure what you mean by "return" in this context, but you can
> select them using XPath, this would be
>
> //node()[count(node()) >= 2]
>
> Or if you mean elements rather than nodes
>
> //*[count(*) >= 2]
>
> See the MSDN documentation on how to use XPath in your application.
> --
> Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
> Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
> 68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
| |
| Bjoern Hoehrmann 2005-02-23, 7:18 am |
| * Jerry West wrote in microsoft.public.xml:
>Thank you for the reply. I tried the 1st example below but this always
>returns an error that states "Unknown Method". The error indicates the
>unknown method is: -->count(node<--
You might be using MSXML 2.x then, you can download MSXML 3.x from MSDN,
or MSXML 4.x in fact.
>I tried changing the statement various ways thinking that the word "node"
>should be changed to reflect the Node name in the XML fragment I showed. For
>example:
No, node() is a functional notation. You can replace it of course, but
>//node()[count(Key()) >= 2]
That would only work if there is a Key() function taking no parameters,
>//Order/()[count(Key()) >= 2]
^^^
That's not legal syntax,
>//node()[count(node(Key)) >= 2]
That's not legal syntax for the node() functional notation either...
If you want to look only for nodes that have two or more "Key" element
children you can use
//node()[count(Key) >= 2]
For all Order elements with two or more Key element children you'd use
//Order[count(Key) >= 2]
The examples in http://www.w3.org/TR/xpath#location-paths might help.
--
Björn Höhrmann · mailto:bjoern@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|