Hi,
The statement Imports System.XML underlines to be an error in my form. What am I missing here ?
thanks.
Printable View
Hi,
The statement Imports System.XML underlines to be an error in my form. What am I missing here ?
thanks.
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)
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?
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
is invalid, it would have to be like this: <TIRE_BRAND>LANCOME</TIRE_BRAND>Quote:
<BRAND>LANCOME</TIRE_BRAND>
However, I'm still learning XML, so I may be wrong.