XML File - Select Individual Data Items

B

Ben

Hi

I am a newbe when it comes to XML. I have the Schema below:

<XMLRoot xmlns="http://tempuri.org/xmlTesting.xsd">
<Data1>
<Country>My First Country</Country>
<Town>My Town</Town>
<Link>http://www.MyWebsite.com/</Link>
</Data1>
</XMLRoot>

I can databind a grid etc, but want to work with individual items, I want to
do a number of things:

1) get a distinct list of all countries
2) get all towns and links for a specific country

I will then loop though the results and list them in an ASPX page

Any advice on how to do this would be much appricated.

Thanks
B

PS we are currently using framework 1.1
 
A

AMDRIT

There are a plethera of ways to start, a bit of a learning curve to
overcome.

Without even using utilities that are available in the System.XML namespace,
you can accomplish your tasks.

Take a look at SelectNodes()
Take a look at SelectSingleNode()

Take a look at dictionary and hashtable objects
Take a look at dataset and datatable objects

Then you can make it more simple and delve deeper into the utilities
provided within the XML namespace.
 
B

Ben

Hi

Thanks for your post, I have researched as you say and have a good solution
except I am having problems alphabetically sorting the results:

'load the xml file

Dim xtr As XmlTextReader = New
XmlTextReader(Server.MapPath(gstrXMLCountries))

xtr.WhitespaceHandling = WhitespaceHandling.None

Dim xd As XmlDocument = New XmlDocument

xd.Load(xtr)

'retrieve matching nodes

Dim xnl As XmlNodeList = xd.DocumentElement.SelectNodes(tbXPath.Text)

'output the results

lblOutput.Text = ""

Dim xnod As XmlNode

For Each xnod In xnl

'for elements display the corresponding text entity

If xnod.NodeType = XmlNodeType.Element Then

lblOutput.Text += (xnod.NodeType.ToString & ": " & xnod.Name & " = " &
xnod.FirstChild.Value & "&lt;br/&gt;")

Else

lblOutput.Text += (xnod.NodeType.ToString & ": " & xnod.Name & " = " &
xnod.Value & "&lt;br/&gt;")

End If

Next

'clean up

xtr.Close()

Any help would be much appreicated

Thanks

B
 

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

Top