|
-
Feb 13th, 2007, 09:42 AM
#1
Thread Starter
Fanatic Member
[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.
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Feb 13th, 2007, 09:56 AM
#2
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
-
Feb 13th, 2007, 11:28 AM
#3
Thread Starter
Fanatic Member
Re: Using xml childnode name instead of index
Works perfectly.
Thanks

If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|