|
-
Mar 3rd, 2005, 06:08 PM
#1
Thread Starter
Junior Member
[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.
-
Mar 3rd, 2005, 06:10 PM
#2
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)
-
Mar 4th, 2005, 08:54 AM
#3
Thread Starter
Junior Member
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:
Dim reader As New XmlTextReader("C:\tirebrand.xml")
While reader.Read()
cb1.Items.Add(reader.Name)
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.
-
Mar 6th, 2005, 07:12 AM
#4
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:
Private Sub LoadXML()
Dim XMLDocument As New XMLDocument
XMLDocument.Load("[i]Filename[/i]")
For Each Brand As XmlNode In XMLDocument.SelectNodes("[i]RootNode[/i]/Brand")
cb1.Items.Add(Brand.SelectSingleNode("BRAND_CODE").InnerText)
cb2.Items.Add(Brand.SelectSingleNode("TIRE_BRAND").InnerText)
Next
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|