473,395 Members | 1,471 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

XPath related question

on my page I have a DropDownList and a label. My DropDownList is filled from
an xml file using XPathNavigator. What I want to do is when the user selects
a value from my DropDownList I want a certain node to be selected from an
XPathNodeIterator and I want the value of its attribute displayed in the
Label on my page.

Here is my code:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim xpd As XPathDocument = New
XPathDocument(Server.MapPath("weather.xml"))
' Get the associated navigator
Dim xpn As XPathNavigator = xpd.CreateNavigator()

Dim strDate, strLine As String
Dim arrDate() As String
If Not IsPostBack Then
' Retrieve nodes to match the expression
Dim xpni As XPathNodeIterator = xpn.Select("//day")
' And dump the results
ddl1.Items.Clear()
While xpni.MoveNext
ddl1.Items.Add(xpni.Current.GetAttribute("t", String.Empty)
& " " & xpni.Current.GetAttribute("dt", String.Empty))
End While
Else

strLine = Trim(ddl1.SelectedItem.Text)
arrDate = strLine.Split(" ")
strDate = arrDate(1) & " " & arrDate(2)
Dim xpni2 As XPathNodeIterator = xpn.Select("//day[./@dt='" &
strDate & "']")
<!--The problem starts here. I don't seem to be able to retrieve the child
node "part" and it's attribute "p" where "p='d'" from my XPathNodeiterator
xpdi2-->
lblDay.Text =
xpni2.Current.SelectChildren(".//part[./@p='d']").Current.ToString
''lblDay.Text =
xpni2.Current.Select(".//part[./@p='d']").Current.ToString

'lblDay.Text =
xpni2.Current.SelectChildren(".//part[./@p='d']").Current.ToString
<!-- end//-->

End If
End Sub

Here is a copy of my weather.xml file:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<weather ver="2.0">
<dayf>
<lsup>5/13/05 3:09 PM EDT</lsup>
<day d="0" t="Friday" dt="May 13">
<hi>N/A</hi>
<low>50</low>
<sunr>5:47 AM</sunr>
<suns>8:07 PM</suns>
<part p="d">
<icon>44</icon>
<t>N/A</t>
<wind>
<s>N/A</s>
<gust>N/A</gust>
<d>N/A</d>
<t>N/A</t>
</wind>
<bt>N/A</bt>
<ppcp>20</ppcp>
<hmid>N/A</hmid>
</part>
<part p="n">
<icon>33</icon>
<t>Mostly Clear</t>
<wind>
<s>8</s>
<gust>N/A</gust>
<d>183</d>
<t>S</t>
</wind>
<bt>M Clear</bt>
<ppcp>20</ppcp>
<hmid>62</hmid>
</part>
</day>
<day d="1" t="Saturday" dt="May 14">
<hi>81</hi>
<low>65</low>
<sunr>5:47 AM</sunr>
<suns>8:08 PM</suns>
<part p="d">
<icon>37</icon>
<t>Isolated T-Storms</t>
<wind>
<s>11</s>
<gust>N/A</gust>
<d>204</d>
<t>SSW</t>
</wind>
<bt>Iso T-Storms</bt>
<ppcp>30</ppcp>
<hmid>58</hmid>
</part>
<part p="n">
<icon>47</icon>
<t>Scattered T-Storms</t>
<wind>
<s>9</s>
<gust>N/A</gust>
<d>199</d>
<t>SSW</t>
</wind>
<bt>Sct T-Storms</bt>
<ppcp>50</ppcp>
<hmid>72</hmid>
</part>
</day>
<day d="2" t="Sunday" dt="May 15">
<hi>78</hi>
<low>54</low>
<sunr>5:46 AM</sunr>
<suns>8:09 PM</suns>
<part p="d">
<icon>37</icon>
<t>Isolated T-Storms</t>
<wind>
<s>10</s>
<gust>N/A</gust>
<d>254</d>
<t>WSW</t>
</wind>
<bt>Iso T-Storms</bt>
<ppcp>30</ppcp>
<hmid>55</hmid>
</part>
<part p="n">
<icon>11</icon>
<t>Showers</t>
<wind>
<s>3</s>
<gust>N/A</gust>
<d>301</d>
<t>WNW</t>
</wind>
<bt>Showers</bt>
<ppcp>60</ppcp>
<hmid>62</hmid>
</part>
</day>
<day d="3" t="Monday" dt="May 16">
<hi>69</hi>
<low>49</low>
<sunr>5:45 AM</sunr>
<suns>8:10 PM</suns>
<part p="d">
<icon>30</icon>
<t>Partly Cloudy</t>
<wind>
<s>7</s>
<gust>N/A</gust>
<d>9</d>
<t>N</t>
</wind>
<bt>P Cloudy</bt>
<ppcp>20</ppcp>
<hmid>53</hmid>
</part>
<part p="n">
<icon>11</icon>
<t>Showers</t>
<wind>
<s>4</s>
<gust>N/A</gust>
<d>66</d>
<t>ENE</t>
</wind>
<bt>Showers</bt>
<ppcp>30</ppcp>
<hmid>66</hmid>
</part>
</day>
<day d="4" t="Tuesday" dt="May 17">
<hi>67</hi>
<low>47</low>
<sunr>5:44 AM</sunr>
<suns>8:11 PM</suns>
<part p="d">
<icon>30</icon>
<t>Partly Cloudy</t>
<wind>
<s>10</s>
<gust>N/A</gust>
<d>46</d>
<t>NE</t>
</wind>
<bt>P Cloudy</bt>
<ppcp>20</ppcp>
<hmid>55</hmid>
</part>
<part p="n">
<icon>11</icon>
<t>Showers</t>
<wind>
<s>3</s>
<gust>N/A</gust>
<d>30</d>
<t>NNE</t>
</wind>
<bt>Showers</bt>
<ppcp>30</ppcp>
<hmid>60</hmid>
</part>
</day>
</dayf>
</weather>

Nov 19 '05 #1
0 1040

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: kj | last post by:
Suppose I have some XML document that contains tags of the form <... xmlns:foo="http://www.bar.org/foo"> <... xmlns:foo="baz"> <... xmlns:frobozz="http://www.bar.org/foo"> What's the...
0
by: Oleg Paraschenko | last post by:
Hello, might be of some interest: find with XPath over file system http://uucode.com/texts/xfind/index.html <quote> The standard UNIX utility find now supports XPath:
3
by: Kathy Burke | last post by:
Hi again, I'm using the following xpath (works in visualizer) with a SelectSingleNode("xpath") statement. //Station/(WI])]/@order Problem is I get an error "expression passed to this method...
4
by: Andreas Håkansson | last post by:
I have a price of XML that looks like this <Root> <SomeNode> ..... </SomeNode> <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"> ... </Signature> </Root>
2
by: Jesper Denmark | last post by:
I use Xpath to retrieve nodes in a document like : doc.SelectSingleNode("/properties/layer"); - however this is not very robust as I'm only query on text. What if width='0.200' instead of...
9
by: David Thielen | last post by:
Hi; I am sure I am missing something here but I cannot figure it out. Below I have a program and I cannot figure out why the xpath selects that throw an exception fail. From what I know they...
1
by: chriscorbell | last post by:
I'm fairly new to XSLT and XPath. My question is related to some posts I found in group archives (e.g. "Disable XPath namespace matching in XSL") but is a little more specific. I want a single...
5
by: Gnic | last post by:
Hi , I have an XmlDocument instance, I want to find a node in the xml, but I don't know it's path until runtime, for example <aaa> <bbb name="x"/> <aaa attr="y"> <ccc>sometext</ccc> </aaa>
6
by: Gale | last post by:
I'm working on something in jQuery with XPath What I want to do is: if checkbox is checked, set background color od label that contain input(checkbox) to red I have this code:...
3
by: bruce | last post by:
for guys with python/xpath expertise.. i'm playing with xpath.. and i'm trying to solve an issue... i have the following kind of situation where i'm trying to get certain data. i have a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.