searching for xml nodes

H

helpful sql

Hi all,
Following is a sample code from my xml file.

<w:body>
<ns0:Mpi>
<ns0:User>
<ns0:Address1>

</ns0:Address1>
</ns0:User>
</ns0:Mpi>
</w:body>

I first need to reference the User node and I am able to achieve it using
the following line. When this line executes, I do have nodeListTable
variable referencing the User node.
XmlNodeList nodeListTable =
nodeDataset.SelectNodes("//ns0:User",coverLetterSectionTemplateMamespaceManager);

But then I need to reference the Address1 node using the above nodeListTable
variable. I tried the following line

XmlNodeList nodeListField =
nodeListTable[0].SelectNodes("//ns0:*",coverLetterSectionTemplateMamespaceManager)

But after this line executes the nodeListField variable contains all nodes
in the ns0 namespace including Mpi and User nodes. So my question is how can
I select Address1 node from nodeListTable variable using SelectNodes
function?

Thanks in advance.
 
B

Brock Allen

When you loop over the XmlNodes in the list, just issue a SelectSingleNode("./Address").
This will be executed in the context of the User node (from your list).
 
K

Kai Brinkmann [MSFT]

Try the following:

nodeListTable[0].SelectNodes("./ns0:*",coverLetterSectionTemplateMamespaceManager)

The period selects the current node, so this expression will select all
"ns0:*" nodes that are children of the current node.

BTW, you don't have to use SelectNodes() at all. Since nodeListTable[0]
already return a single node, why don't you just use that node's child node
collection. For your XML sample document below

nodeListTable[0].FirstChild

will also give you what you need.

--
Kai Brinkmann [MSFT]

Please do not send e-mail directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top