Results 1 to 3 of 3

Thread: [RESOLVED] Using xml childnode name instead of index

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    Resolved [RESOLVED] Using xml childnode name instead of index

    Hi guys,
    I have the following code:
    VB Code:
    1. Private doc As XmlDocument
    2.     Private sNodelist As XmlNodeList
    3.     Private sNode As XmlNode
    4.  
    5.             doc = New XmlDocument()
    6.             reader = New XmlTextReader(frmSchedule.currentSchedule)
    7.             doc.Load(reader)
    8.             sNodelist = doc.SelectNodes("/schedule/visit")
    9.                 With sqlCmd
    10.                 ' loop through each visit node
    11.                 For Each sNode In sNodelist
    12.                     .CommandText = "SELECT COUNT(*) FROM visits WHERE visitID = @visitID AND sDate = @sDate"
    13.                     .Parameters.Add(New SqlCeParameter("@visitID", sNode.ChildNodes.Item(0).InnerText.ToString()))
    14.                     .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

  2. #2
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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:
    1. snode.Item("namehere").InnerText

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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
  •  



Click Here to Expand Forum to Full Width