|
-
Jun 19th, 2006, 02:28 PM
#1
Thread Starter
Hyperactive Member
Xml [Resolved]
I'm still struggling with XML. I have this XML file with hundreds of blocks that look like this:
<entry>
<name></name>
<website></website>
<username></username>
<password></password>
</entry>
How do I ready every "entry" and get the "name" and "website" into a listbox like: name ( website )
Last edited by tylerm; Jun 19th, 2006 at 04:55 PM.
Reason: Resolved
-
Jun 19th, 2006, 02:32 PM
#2
Re: Xml
is there a top level node of the XML? <entry> can't be the root in a well formed XML doc, as they are only supposed to have one root element... so is it something like
Code:
<entries>
<entry>
<name></name>
<website></website>
<username></username>
<password></password>
</entry>
<entry>
<name></name>
<website></website>
<username></username>
<password></password>
</entry>
</entries>
-
Jun 19th, 2006, 02:33 PM
#3
Thread Starter
Hyperactive Member
Re: Xml
yes, there is a top level called <mcbr>, but yes.
-
Jun 19th, 2006, 02:34 PM
#4
Re: Xml
ok.. will post some example code.. give me a minute
-
Jun 19th, 2006, 03:09 PM
#5
Re: Xml
ok here is some sample code..
if you don't understand it fully, and want to see it in action, you will need to stick this code in a form, and add a listbox (listbox1)
You would also need to put the xml document in the bin directory (where your exe is) and change my code's "testdata.xml" to whatever your XML file is actually called.
VB Code:
Dim XDoc As New Xml.XmlDocument
Try
'LOAD FILE INTO OBJECT
XDoc.Load(Application.StartupPath & "\testdata.xml")
'LOOP ALL THE CHILD NODES OF THE DOCUMENT'S DOCUMENTELEMENT PROPERTY
For Each XNode As Xml.XmlNode In XDoc.DocumentElement.ChildNodes
ListBox1.Items.Add(XNode.Item("name").InnerText)
ListBox1.Items.Add(ControlChars.Tab & XNode.Item("website").InnerText)
ListBox1.Items.Add(ControlChars.Tab & XNode.Item("username").InnerText)
ListBox1.Items.Add(ControlChars.Tab & XNode.Item("password").InnerText)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
-
Feb 28th, 2007, 03:36 PM
#6
Frenzied Member
Re: Xml [Resolved]
Hmm I post this
vb Code:
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
ListBox1.Items.Clear()
Dim XDoc As New Xml.XmlDocument
Try
'LOAD FILE INTO OBJECT
XDoc.Load("C:\Documents and Settings\Owner\Desktop\newslist.xml")
'LOOP ALL THE CHILD NODES OF THE DOCUMENT'S DOCUMENTELEMENT PROPERTY
For Each XNode As Xml.XmlNode In XDoc.DocumentElement.ChildNodes
ListBox1.Items.Add(XNode.Item("rssid").InnerText)
'ListBox1.Items.Add(ControlChars.Tab & XNode.Item("title").InnerText)
'ListBox1.Items.Add(ControlChars.Tab & XNode.Item("link").InnerText)
Next
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
End Sub
But I get the messagebox saying "Object reference not set to an instance of an object"
How can i fix this???
-
Feb 28th, 2007, 04:21 PM
#7
Re: Xml [Resolved]
what does newslist.xml look like?
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
|