home

my blog

check me out!

Using Xpath programmatically with filtered results

Dim xmlPath As String = Server.MapPath("AmazonTravel.xml")
Dim xPath As String = "//album[@id='" & Request.QueryString("album") & "']/Keywords"

Dim doc As New XmlDocument()
doc.Load(xmlPath)
Dim nodeList As XmlNodeList = doc.DocumentElement.SelectNodes(XPath)
Dim child As XmlNode
For Each child In nodeList
    Label1.Text = child.FirstChild.Value
Next child 

AmazonTravel.xml:

<?xml version='1.0'?>
<!-- This file represents a fragment of a travel album database -->
<Amazon>
  <album id="Salzburg">
    <Keywords>Salzburg</Keywords>
    <Location>Mozarts Geburtshaus, Salzburg, Austria</Location>
  </album>
  <album id="Villach">
    <Keywords>Travel Austria</Keywords>
    <Location>Villach, Austria</Location>
  </album>
  <album id="Brussels">
    <Keywords>Travel Brussels</Keywords>
    <Location>Brussels, Belgium</Location>
  </album>
  <album id="Antwerpen">
    <Keywords>Travel Belgium</Keywords>
    <Location>Antwerpen, Belgium</Location>
</album>
</Amazon>

Add comment


  • Comment
  • Preview
Loading