470,641 Members | 1,541 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,641 developers. It's quick & easy.

XML XPath question. Simple XML File

Ok,

Here is my XML File, it's pretty simple:
<?xml version="1.0" encoding="utf-8" ?>
<Dispositions>
<Group Name="Unused">
<Disp>NA</Disp>
<Disp>TCB</Disp>
<Disp>WPC</Disp>
</Group>
<Group Name="Refusals">
<Disp>PM</Disp>
<Disp>REF</Disp>
<Disp>SVN</Disp>
<Disp>SFV</Disp>
<Disp>KO</Disp>
<Disp>UNV</Disp>
<Disp>VTCB</Disp>
</Group>
<Group Name="Voids">
<Disp>AO</Disp>
<Disp>DISC</Disp>
<Disp>INEL</Disp>
<Disp>LB</Disp>
<Disp>MC</Disp>
<Disp>WRN</Disp>
</Group>
<Group Name="Sales">
<Disp>RS</Disp>
<Disp>SALE</Disp>
<Disp>SI</Disp>
<Disp>SIE</Disp>
<Disp>VS</Disp>
<Disp>WCS</Disp>
</Group>
<Group Name="DNC">
<Disp>DNC</Disp>
</Group>
</Dispositions>
Here is the code I am using:

Dim doc As System.Xml.XmlDocument
doc = New XmlDocument
doc.Load("Dispositions.xml")
Dim Root As XmlElement = doc.DocumentElement
Dim node As XmlNodeList
node = Root.SelectNodes("/Dispositions/Group/@Name")
Dim i As Integer
Dim j As Integer
For i = 0 To node.Count - 1 Step i + 1
Debug.WriteLine("-" & node.Item(i).Value)
Dim sNodes As XmlNodeList =
node(i).SelectNodes("/Dispositions/Group[Name=" & node.Item(i).Value &
"]/Disp/text()")
For j = 0 To sNodes.Count - 1 Step j + 1
Debug.WriteLine("--" & sNodes.Item(j).Value)
Next
Next
Right now it only lists this:

-Unused
-Refusals
-Voids
-Sales
-DNC

What I want to do is, depending on the user, they will click a button
that will grab all <Disp> underneath a specific <Group
name="whatever"></Group>

These are actually codes to be used in a sql query that will grab
certain records.

This is my first time working with XML in dotnet and I am quite
confused. Where can i go to get a basic understanding of the Nodes,
Nodelists, etc....

Can anyone tell me how to accomplish what it is i'm trying to do here.
thank you.
Nov 12 '05 #1
2 1544
Ice
Where can you go?

Framework SDK.

maybe this will work..

assuming vName is the selection

/Group[@Name=vname]

ice

"DKode" <dk***@cfl.rr.com> wrote in message
news:b1**************************@posting.google.c om...
Ok,

Here is my XML File, it's pretty simple:
<?xml version="1.0" encoding="utf-8" ?>
<Dispositions>
<Group Name="Unused">
<Disp>NA</Disp>
<Disp>TCB</Disp>
<Disp>WPC</Disp>
</Group>
<Group Name="Refusals">
<Disp>PM</Disp>
<Disp>REF</Disp>
<Disp>SVN</Disp>
<Disp>SFV</Disp>
<Disp>KO</Disp>
<Disp>UNV</Disp>
<Disp>VTCB</Disp>
</Group>
<Group Name="Voids">
<Disp>AO</Disp>
<Disp>DISC</Disp>
<Disp>INEL</Disp>
<Disp>LB</Disp>
<Disp>MC</Disp>
<Disp>WRN</Disp>
</Group>
<Group Name="Sales">
<Disp>RS</Disp>
<Disp>SALE</Disp>
<Disp>SI</Disp>
<Disp>SIE</Disp>
<Disp>VS</Disp>
<Disp>WCS</Disp>
</Group>
<Group Name="DNC">
<Disp>DNC</Disp>
</Group>
</Dispositions>
Here is the code I am using:

Dim doc As System.Xml.XmlDocument
doc = New XmlDocument
doc.Load("Dispositions.xml")
Dim Root As XmlElement = doc.DocumentElement
Dim node As XmlNodeList
node = Root.SelectNodes("/Dispositions/Group/@Name")
Dim i As Integer
Dim j As Integer
For i = 0 To node.Count - 1 Step i + 1
Debug.WriteLine("-" & node.Item(i).Value)
Dim sNodes As XmlNodeList =
node(i).SelectNodes("/Dispositions/Group[Name=" & node.Item(i).Value &
"]/Disp/text()")
For j = 0 To sNodes.Count - 1 Step j + 1
Debug.WriteLine("--" & sNodes.Item(j).Value)
Next
Next
Right now it only lists this:

-Unused
-Refusals
-Voids
-Sales
-DNC

What I want to do is, depending on the user, they will click a button
that will grab all <Disp> underneath a specific <Group
name="whatever"></Group>

These are actually codes to be used in a sql query that will grab
certain records.

This is my first time working with XML in dotnet and I am quite
confused. Where can i go to get a basic understanding of the Nodes,
Nodelists, etc....

Can anyone tell me how to accomplish what it is i'm trying to do here.
thank you.

Nov 12 '05 #2
You have one small typo in your 2nd "SelectNodes"
statement.

The "Name" attribute is referenced by "@Name", not
just "Name". If you stick a "@" in front of "Name" in the
snippet below your code will work

node(i).SelectNodes("/Dispositions/Group[Name=" & node.Item
(i).Value &
"]/Disp/text()")

-----Original Message-----
Ok,

Here is my XML File, it's pretty simple:
<?xml version="1.0" encoding="utf-8" ?>
<Dispositions>
<Group Name="Unused">
<Disp>NA</Disp>
<Disp>TCB</Disp>
<Disp>WPC</Disp>
</Group>
<Group Name="Refusals">
<Disp>PM</Disp>
<Disp>REF</Disp>
<Disp>SVN</Disp>
<Disp>SFV</Disp>
<Disp>KO</Disp>
<Disp>UNV</Disp>
<Disp>VTCB</Disp>
</Group>
<Group Name="Voids">
<Disp>AO</Disp>
<Disp>DISC</Disp>
<Disp>INEL</Disp>
<Disp>LB</Disp>
<Disp>MC</Disp>
<Disp>WRN</Disp>
</Group>
<Group Name="Sales">
<Disp>RS</Disp>
<Disp>SALE</Disp>
<Disp>SI</Disp>
<Disp>SIE</Disp>
<Disp>VS</Disp>
<Disp>WCS</Disp>
</Group>
<Group Name="DNC">
<Disp>DNC</Disp>
</Group>
</Dispositions>
Here is the code I am using:

Dim doc As System.Xml.XmlDocument
doc = New XmlDocument
doc.Load("Dispositions.xml")
Dim Root As XmlElement = doc.DocumentElement
Dim node As XmlNodeList
node = Root.SelectNodes ("/Dispositions/Group/@Name") Dim i As Integer
Dim j As Integer
For i = 0 To node.Count - 1 Step i + 1
Debug.WriteLine("-" & node.Item(i).Value)
Dim sNodes As XmlNodeList =
node(i).SelectNodes("/Dispositions/Group[Name=" & node.Item(i).Value &"]/Disp/text()")
For j = 0 To sNodes.Count - 1 Step j + 1
Debug.WriteLine("--" & sNodes.Item (j).Value) Next
Next
Right now it only lists this:

-Unused
-Refusals
-Voids
-Sales
-DNC

What I want to do is, depending on the user, they will click a buttonthat will grab all <Disp> underneath a specific <Group
name="whatever"></Group>

These are actually codes to be used in a sql query that will grabcertain records.

This is my first time working with XML in dotnet and I am quiteconfused. Where can i go to get a basic understanding of the Nodes,Nodelists, etc....

Can anyone tell me how to accomplish what it is i'm trying to do here.thank you.
.

Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by mig | last post: by
7 posts views Thread by Sebastian Petzelberger | last post: by
7 posts views Thread by Ot | last post: by
3 posts views Thread by bruce | last post: by
7 posts views Thread by Tim Hallwyl | last post: by
reply views Thread by Curtin1060 | last post: by
1 post views Thread by Korara | last post: by
???
1 post views Thread by Stoney L | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.