Results 1 to 7 of 7

Thread: reading from xml file...pls help

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24

    Thumbs down reading from xml file...pls help

    hi all,

    i'm trying to read from a xml file, get its data and load into a drop down list.

    But i cant get the method rite.

    Hope someone can point it out for mi with some examples. Thankx!

    <?xml version="1.0" standalone="no"?>
    <!--Same as generated by serializing, SAS_Student-->
    <SAS_Course>
    <Course_Code>DNDF01</Course_Code>
    <Course_Code>ITSP01</Course_Code>
    <Course_Code>ITDF03</Course_Code>
    <Course_Code>ITDF01</Course_Code>
    <Course_Code>ITDP03</Course_Code>
    <Course_Code>DNDF02</Course_Code>
    </SAS_Course>

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Set a reference to the System.Xml namespace and use code simular to this.
    VB Code:
    1. Dim doc As New System.Xml.XmlDocument()
    2. Dim root As System.Xml.XmlNode
    3. doc.Load("c:\mydoc.xml")
    4. root = doc.FirstChild
    5. Do While root.NodeType <> Xml.XmlNodeType.Element
    6.     root = root.NextSibling
    7. Loop
    8. If root.HasChildNodes Then
    9.     Dim i As Integer
    10.     For i = 0 To root.ChildNodes.Count - 1
    11.         ComboBox1.Items.Add(root.ChildNodes(i).InnerText)
    12.     Next
    13. End If
    Best regards

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24
    thank you Joacim Andersson, i'll go try it out.....
    thank you very much!!!

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24
    Joacim Andersson, i'm sorry to trouble you again.

    i've tried to use your sample codes but the system prompt that the "Xml" in "Xml.XmlNodeType.Element" is an ambiguous term...

    is there any thing that i forget to import??

    Imports System.Data
    Imports System.Data.Common
    Imports System.Data.SqlClient

    Imports System.Xml
    Imports System.Xml.Serialization
    Imports System.Xml.Xsl

  5. #5
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Have you set a reference to the System.Xml namespace?
    It's not enough to Import it.
    Importing is just so you don't have to include the full "path" of the namespace so instead of doing a declaration like this:
    VB Code:
    1. Dim doc As New System.Xml.XmlDocument()
    You could simply do this
    VB Code:
    1. Dim doc As New XmlDocument()
    To set a reference right click the Reference node in the Solution Explorer window and click Add Reference.
    Then double click the item in the list named System.Xml.dll

    Best regards

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Nov 2001
    Location
    Singapore
    Posts
    24
    thank you....

    it worked already...

    beside your way, it can also be solved by importing System...

    by the way...really thank you...=)

  7. #7
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649
    Well, you still have to set a reference to the System.Xml namespace.
    But you're correct in that if you want to use Xml.XmlNodeType.Element you should import the System namespace.
    Otherwise you should type System.Xml.XmlNodeType.Element

    But I'm glad you've got it working.

    Have fun

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