|
-
Dec 6th, 2001, 02:44 AM
#1
Thread Starter
Junior Member
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>
-
Dec 6th, 2001, 11:02 AM
#2
Set a reference to the System.Xml namespace and use code simular to this.
VB Code:
Dim doc As New System.Xml.XmlDocument()
Dim root As System.Xml.XmlNode
doc.Load("c:\mydoc.xml")
root = doc.FirstChild
Do While root.NodeType <> Xml.XmlNodeType.Element
root = root.NextSibling
Loop
If root.HasChildNodes Then
Dim i As Integer
For i = 0 To root.ChildNodes.Count - 1
ComboBox1.Items.Add(root.ChildNodes(i).InnerText)
Next
End If
Best regards
-
Dec 6th, 2001, 09:15 PM
#3
Thread Starter
Junior Member
thank you Joacim Andersson, i'll go try it out.....
thank you very much!!!
-
Dec 6th, 2001, 09:55 PM
#4
Thread Starter
Junior Member
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
-
Dec 7th, 2001, 12:06 AM
#5
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:
Dim doc As New System.Xml.XmlDocument()
You could simply do this
VB Code:
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
-
Dec 7th, 2001, 01:10 AM
#6
Thread Starter
Junior Member
thank you....
it worked already...
beside your way, it can also be solved by importing System...
by the way...really thank you...=)
-
Dec 7th, 2001, 01:21 AM
#7
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|