[RESOLVED] Using xml childnode name instead of index
Hi guys,
I have the following code:
VB Code:
Private doc As XmlDocument
Private sNodelist As XmlNodeList
Private sNode As XmlNode
doc = New XmlDocument()
reader = New XmlTextReader(frmSchedule.currentSchedule)
doc.Load(reader)
sNodelist = doc.SelectNodes("/schedule/visit")
With sqlCmd
' loop through each visit node
For Each sNode In sNodelist
.CommandText = "SELECT COUNT(*) FROM visits WHERE visitID = @visitID AND sDate = @sDate"
.Parameters.Add(New SqlCeParameter("@visitID", sNode.ChildNodes.Item(0).InnerText.ToString()))
.Parameters.Add(New SqlCeParameter("@sDate", sNode.ChildNodes.Item(1).InnerText.ToString()))
And i was wondering whether it was possible to change the index from an integer to the name of the child node as i have another xml file that i want to use this code for but the ordering is different so using numbers is impossible.
Thanks in advance for any help. If theres any extra information you need i'll gladly provide it.
:afrog:
Re: Using xml childnode name instead of index
try declaring sNode as an XMLElement instead of an XMLNode (xmlelement inherits from xmlnode)
once you have changed the datatype, try accessing the child nodes like
VB Code:
snode.Item("namehere").InnerText
Re: Using xml childnode name instead of index
Works perfectly.
Thanks
:thumb:
:wave: