|
-
Oct 25th, 2004, 11:01 AM
#1
Thread Starter
Addicted Member
VB.NET: Getting Attributes and Text out from Xml 2....[Resolved]
Say I have this Xml taken from one of the threads as example:
Code:
<Settings>
<Connection>
<UserID>sa</UserID>
<DataSource>Server</DataSource>
<InitialCatalog>Database</InitialCatalog>
</Connection>
</Settings>
To get the Xml text is:
Code:
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
m_xmld = New XmlDocument()
m_xmld.Load("Settings.xml")
m_nodelist = m_xmld.SelectNodes("/Settings/Connection")
For Each m_node In m_nodelist
Dim UserID = m_node.ChildNodes.Item(0).InnerText
Dim DataSource = m_node.ChildNodes.Item(1).InnerText
Dim InitialCatalog = m_node.ChildNodes.Item(2).InnerText
Next
How about if i add in one time tag...
Code:
<Settings>
<Connection>
<UserID>sa</UserID>
<DataSource>Server</DataSource>
<InitialCatalog>Database</InitialCatalog>
<Time hour="23" min="40">
</Connection>
<Connection>
<UserID>sa</UserID>
<DataSource>Server</DataSource>
<InitialCatalog>Database</InitialCatalog>
<Time hour="23" min="40">
</Connection>
</Settings>
How do i use the above node.ChildNodes method to get the "23" or "40" out from the Xml tag....
I need to loop through all the nodes...and I am using XmlDocument...
Any suggestion or link will be appreciated...
Thanks
Last edited by toytoy; Dec 3rd, 2004 at 07:51 AM.
-
Oct 25th, 2004, 11:05 AM
#2
Should be
m_node.ChildNodes.Item(3).Attributes(0).Value for hour
change to Attributes(1) for min
-
Oct 25th, 2004, 11:34 AM
#3
Thread Starter
Addicted Member
What about the below Xml..
Code:
<Settings>
<Connection>
<UserID>sa</UserID>
<DataSource>Server</DataSource>
<InitialCatalog>Database</InitialCatalog>
<Register>
<Time hour="23" min="40">
<Date>22/10/78</Date>
</Register>
</Connection>
<Connection>
<UserID>sa</UserID>
<DataSource>Server</DataSource>
<InitialCatalog>Database</InitialCatalog>
<Register>
<Time hour="23" min="40">
<Date>22/10/78</Date>
</Register>
</Connection>
</Settings>
How to loop using the same nod.ChildNode method to extract the hour, min and DataSource...
Thanks..
Last edited by toytoy; Dec 3rd, 2004 at 07:52 AM.
-
Oct 25th, 2004, 11:29 PM
#4
Thread Starter
Addicted Member
Cander...the code give me an error:
Code:
Additional information: The index being passed in is out of range.
My coding:
Code:
Dim xdoc As New XmlDocument
xdoc.Load("Setting.xml")
Dim nodlist As XmlNodeList
Dim nod As XmlNode
nodlist = xdoc.SelectNodes("//Setting/Connection")
For Each nod In nodlist
Dim hour = nod.ChildNodes.Item(3).Attributes(0).Value
listbox.Items.Add(hour)
Dim min = nod.ChildNodes.Item(3).Attributes(1).Value
listbox.Items.Add(min)
Dim dataSource = nod.ChildNodes.Item(1).InnerText
listbox.Items.Add(dataSource)
Next
Anyone can help...
Thanks
Last edited by toytoy; Dec 3rd, 2004 at 07:52 AM.
-
Oct 26th, 2004, 09:59 PM
#5
Thread Starter
Addicted Member
Last edited by toytoy; Dec 3rd, 2004 at 07:52 AM.
-
Oct 27th, 2004, 04:43 AM
#6
Thread Starter
Addicted Member
Last edited by toytoy; Dec 3rd, 2004 at 07:53 AM.
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
|