Results 1 to 4 of 4

Thread: [NOT Resolved] Why does Imports System.XML give an error ?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Angry [NOT Resolved] Why does Imports System.XML give an error ?

    Hi,

    The statement Imports System.XML underlines to be an error in my form. What am I missing here ?

    thanks.
    Last edited by anin; Mar 4th, 2005 at 01:55 PM.

  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: Why does Imports System.XML give an error ?

    you may need to reference it under the references section of your app... but what kind of app is this? it usually is added by default (to a windows app at least)

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2005
    Posts
    25

    Re: Why does Imports System.XML give an error ?

    My XML file looks like:


    Code:
    </xs:choice> 
      </xs:complexType> 
      </xs:element> 
      </xs:schema> 
    - <BRAND> 
      <BRAND_CODE>01</BRAND_CODE> 
      <BRAND>AVON</TIRE_BRAND> 
      </BRAND> 
    - <BRAND> 
      <BRAND_CODE>02</BRAND_CODE> 
      <BRAND>LANCOME</TIRE_BRAND> 
      </BRAND>

    and I have to read this into 2 combo boxes that is brandcode and brandname

    and when I tried something like



    VB Code:
    1. Dim reader As New XmlTextReader("C:\tirebrand.xml")
    2.         While reader.Read()
    3.             cb1.Items.Add(reader.Name)
    4.         End While

    it populates the name tags like "BRAND", "BRAND_CODE", "BRAND"... how do I read the brand code and brand name data and not the tag?
    Last edited by anin; Mar 4th, 2005 at 02:18 PM.

  4. #4
    Frenzied Member Ideas Man's Avatar
    Join Date
    Aug 2002
    Location
    Australia
    Posts
    1,718

    Re: [NOT Resolved] Why does Imports System.XML give an error ?

    So I take it you fixed the original question?

    If so, I found the easiest way to read XML files was with the XML Document class. After you have read the document into the object, you can loop through all the nodes inside it with code like this:

    VB Code:
    1. Private Sub LoadXML()
    2.         Dim XMLDocument As New XMLDocument
    3.  
    4.         XMLDocument.Load("[i]Filename[/i]")
    5.  
    6.         For Each Brand As XmlNode In XMLDocument.SelectNodes("[i]RootNode[/i]/Brand")
    7.             cb1.Items.Add(Brand.SelectSingleNode("BRAND_CODE").InnerText)
    8.             cb2.Items.Add(Brand.SelectSingleNode("TIRE_BRAND").InnerText)
    9.         Next
    10.     End Sub

    Mind you, I've seen lots of errors in your XML file that makes it incorrect. For starters, I think you can only have one root node, you've got many (Unless you didn't supply the top of the file) and this line
    <BRAND>LANCOME</TIRE_BRAND>
    is invalid, it would have to be like this: <TIRE_BRAND>LANCOME</TIRE_BRAND>

    However, I'm still learning XML, so I may be wrong.
    I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)

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