tags:

views:

152

answers:

1

Hi there,

I`m new to Xpath and got a problem. I want all nodes under a specific parent-node! I tried it with this query, but only get an empty result! :(

var ISDN_confs = from x in xdoc.XPathSelectedElements("//member[name='participantOne']//member[name='name']") 
                 select x;

Sample XML:

<methodResponse>
<params>
  <param>
    <value>
      <struct>
        <member>
           <name>calls</name>
              <value>
                <array>
                  <data>
                    <value>
                      <struct>
                        <member>
                           <name>uniqueId</name>
                           <value>
                              <int>6</int>
                           </value>
                         </member>
  <member>
    <name>participantOne</name>
    <value>
        <struct>
            <member>
                <name>uniqueId</name>
                <value>
                    <int>1609</int>
                </value>
            </member>
            <member>
                <name>protocol</name>
                <value>
                    <string>h323</string>
                </value>
            </member>
            <member>
                <name>incoming</name>
                <value>
                    <boolean>1</boolean>
                </value>
            </member>
            <member>
                <name>progress</name>
                <value>
                    <string>connected</string>
                </value>
            </member>
            <member>
                <name>fecc</name>
                <value>
                    <boolean>1</boolean>
                </value>
            </member>
            <member>
                <name>videoCodec</name>
                <value>
                    <string>h264</string>
                </value>
            </member>
            <member>
                <name>audioCodec</name>
                <value>
                    <string>g722</string>
                </value>
            </member>
            <member>
                <name>autoAttendant</name>
                <value>
                    <boolean>0</boolean>
                </value>
            </member>
            <member>
                <name>name</name>
                <value>
                    <string>Test Endpoints</string>
                </value>
            </member>
            <member>
                <name>number</name>
                <value>
                    <string>12345</string>
                </value>
            </member>
            <member>
                <name>ipAddress</name>
                <value>
                    <string>192.168.2.155</string>
                </value>
            </member>
            <member>
                <name>callIdentifier</name>
                <value>
                    <base64>CCCCVVVVVDDDDD</base64>
                </value>
            </member>
        </struct>
    </value>
</member>
<member>
<name>participantTwo</name>
<value>
<struct>
 <member>
 <name>name</name>
 <value>
 <string/>
 </value>
 </member>
 <member>
 <name>number</name>
 <value>
 <string>123456</string>
 </value>
 </member>
 <member>
 <name>channels</name>
 <value>
 <array>
 <data>
 <value>
 <int>1</int>
 </value>
 <value>
 <int>2</int>
 </value>
 </data>
 </array>
 </value>
 </member>
 </struct>
 </value>
 </member>
 </struct>
 </value>

The desired output should be a limited variation of the actual output. So i dont want all the name-members, but the name-members in the two structures without channels-members.

I hope its clear what I want! :)

Sample Output:

<member>
   <name>name</name> 
     <value>
       <string>Test Endpoints</string> 
     </value>
</member>

At the moment, with the above query, I get all name-members, but thats not what I want, like I said in the comments below!

UPDATE--- I tried to get all name-member which have channels-members with this query

var parts = from c in xdoc.XPathSelectElements("//member[name='name']")
                    where c.Element("name").Value == "channels" && c.Element("name").HasElements
                    select c;

but only get an empty result!

+1  A: 

Without seeing a sample document and the desired output it is a bit difficult to see what you actually want, but normally you would just use a single XPath expression which also includes the parent:

"//member[name='participantOne']/member[name='name']"

If this doesn't do what you want you could edit your question to include sample input and output.

Actually your last sentence is a little bit confusing: Is the parent node's name participantOne? And the child node's name is name? Then you could simply write:

"//participantOne/name"

Update

As the member[name='participantOne'] node is not a direct parent but an acestor you would have to use

//member[name='participantOne']//member[name='name']

as your XPath expression.

0xA3
Hi divo,Just edited my Question!
cordellcp3
Thanks divo! //member[name='participantOne']//member[name='name'] worked out fine!
cordellcp3
Is it possible to chnage the xpath-expression to limit the results so that one can say: I want the name-members in the participantOne-structure and the name-members in the partipantTwo-structure?
cordellcp3
Sorry, can you make that a bit clearer, maybe with an example of the desired output?
0xA3
I got a huge xml-file with call-nodes. Every call-node got the structures "participantOne" and "participantTwo"! I want the name-member which has no channels-member in one of the the two "participant"-structures. It is possible that name-members without channels-member are in more than one call-node. I edit the question above with an example xml!
cordellcp3
Sorry, but what is a channel-member? Can you show me a sample output that your query should select (in XML). And by the way, your XML sample is not valid.
0xA3
Hi divo, I think its easier to show you the file instead of copy and paste! I uploaded the file here --> http://rapidshare.de/files/48600758/isdndata_bsp.xml.htmlIn this file you see the channels-member and all other information I`m talking about! :)
cordellcp3
Sample-Output is above!
cordellcp3