Go Back  Xtreme Visual Basic Talk > Visual Basic .NET (2002/2003/2005/2008, including Express editions) > .NET File I/O and Registry > XML question


Reply
 
Thread Tools Display Modes
  #1  
Old 09-15-2007, 03:17 AM
opeca opeca is offline
Regular
 
Join Date: Mar 2007
Posts: 50
Default XML question


Hi all,

I have a simple xml file:

<testxml>

<node1>
node1text
</node1>

<node2>
node2text
</node2>

</testxml>

I've used msxml in vbscript, there was simple to print childnode texts, only I have to move in each childnode, and printing chilnode.name and childnode.text, but in the newer version in vb.net, I cannot get the name of the chilnode with xmltextreader.

I can printing data but the text has no childnodename, and the childnode has no text.

Is there any solution, that I printing out the nodename and the text together?

Thanks
Reply With Quote
  #2  
Old 09-15-2007, 03:01 PM
AtmaWeapon's Avatar
AtmaWeapon AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,416
Default

You haven't posted the code you are using, so I'm only guessing, but I bet that what's happening is that this XML:
Code:
<element>
    text
</element>
Consists of 3 nodes, not the 1 or 2 you might expect. The following information describes both how the XmlTextReader views it and the more versatile and (in my opinion) easier-to-use XmlDocument views it.

<element> is represented with a type of XmlNodeType.Element. text is actually considered a node by both XmlTextReader and XmlDocument; it has a node type of XmlNodeType.Text, and it's Value property will be what you expect. The </element> node is interpreted as a node with type XmlNodeType.EndElement by XmlTextReader and I believe XmlDocument doesn't really return this node.

My guess is you are trying to print the value of one of the element nodes, and by definition they cannot have a value. If you could post code that is representative of what you are doing, you'd get a lot more help.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #3  
Old 09-16-2007, 03:14 AM
opeca opeca is offline
Regular
 
Join Date: Mar 2007
Posts: 50
Default

Thanks Atmaweapon, I tried to approach on another way, not with xmltextreader, just with simple XmlDocument.

So the result is:

Try
Dim m_xmld As XmlDocument
Dim m_nodelist As XmlNodeList
Dim m_node As XmlNode
Dim m_node2 As XmlNode

m_xmld = New XmlDocument()

m_xmld.Load("C:\test.xml")

m_nodelist = m_xmld.SelectNodes("/testnode")

For Each m_node In m_nodelist
For Each m_node2 In m_node.ChildNodes

Dim element = m_node2.InnerText
MsgBox(m_node2.Name + " n " + element)
Next
Next
Catch iserror As Exception
End Try
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->