473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Read XML Text Node Name

All

I am using the code below in order to read an XML file in the format:

<root>
<selection-attr attr="p70">
<value code="Mr">Mr</value>
<value code="Mrs">Mrs</value>
<value code="Ms">Ms</value>
<value code="Miss">Miss</value>
<caption>Title:</caption>
</selection-attr>
</root>

What I am trying to do is identify the element name of the text node ie.
<caption>. On an element node I can use reader.Name but I have been unable
to identify how to read the value for a text node. I would appreciate any
assistance.

Thanks

' ---------
' Code Snippet
'
Dim sr As New System.IO.StreamReader("c:\xml.xml")
Dim sw As New System.IO.StreamWriter("c:\output.txt")
Dim attr As String
Dim doc As New Xml.XmlDocument
doc.Load(sr)
Dim reader As New Xml.XmlNodeReader(doc)

While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "text-attr" Or reader.Name = "selection-attr" Then
attr = reader.GetAttribute("attr")
End If
Case Xml.XmlNodeType.Text
sw.WriteLine(attr & ", " & reader.Name & ", " & reader.Value)
End Select
End While

sw.Close()
Nov 21 '05 #1
1 4467
Use the amlelement object. Once you have the node you want, it is very easy
to change or read the node value, or attribute. Use xpath to find it

Dim xd As New Xml.XmlDocument

'load the xml file
xd.Load("myxml.xml")

'get the value
Dim Node As Xml.XmlElement =
CType(xd.DocumentElement.SelectSingleNode("/selection/caption"),
Xml.XmlElement)

msgbox node.value

"David" wrote:
All

I am using the code below in order to read an XML file in the format:

<root>
<selection-attr attr="p70">
<value code="Mr">Mr</value>
<value code="Mrs">Mrs</value>
<value code="Ms">Ms</value>
<value code="Miss">Miss</value>
<caption>Title:</caption>
</selection-attr>
</root>

What I am trying to do is identify the element name of the text node ie.
<caption>. On an element node I can use reader.Name but I have been unable
to identify how to read the value for a text node. I would appreciate any
assistance.

Thanks

' ---------
' Code Snippet
'
Dim sr As New System.IO.StreamReader("c:\xml.xml")
Dim sw As New System.IO.StreamWriter("c:\output.txt")
Dim attr As String
Dim doc As New Xml.XmlDocument
doc.Load(sr)
Dim reader As New Xml.XmlNodeReader(doc)

While reader.Read()
Select Case reader.NodeType
Case Xml.XmlNodeType.Element
If reader.Name = "text-attr" Or reader.Name = "selection-attr" Then
attr = reader.GetAttribute("attr")
End If
Case Xml.XmlNodeType.Text
sw.WriteLine(attr & ", " & reader.Name & ", " & reader.Value)
End Select
End While

sw.Close()

Nov 21 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
5
by: Richard Lewis | last post by:
Hello Pythoners, I'm currently writing some Python to manipulate a semi-structured XML document. I'm using DOM (minidom) and I've got working code for transforming the document to HTML files and...
2
by: Raghu Gupta | last post by:
Hi, Actually i am facing some problem using quickbooks and presently i am not so expert in using it. I am using c# code to retrive the data from quickbooks. it doesn't matter which language we...
9
by: Adi | last post by:
Hello eveyone, I wanna ask a very simple question here (as it was quite disturbing me for a long time.) My problem is to read a file line by line. I've tried following implementations but still...
2
by: sk.rasheedfarhan | last post by:
Hi , I have to extract a xml file line by line. Here is my xml Step1: <category name= "name" guid="{guid}"state="enabled"> Step2: <rules> Step3: <rule name="rule name" guid="{guid}"...
6
by: | last post by:
Hi, I'm steel trying to read and update my XML file with Visual Basic Express but i am unable to find the right way to read my xml file and update it if neccessary... Here is my problem :...
0
by: jiing | last post by:
Hi all, I want to use sting(the same as Node.Text) to judge if a node exists in TreeView. I've tried several ways, but seems all failed. could anybody help me? Thanks in advance. //My...
8
by: =?Utf-8?B?WVhR?= | last post by:
I want to do the multi-language program, save the language text in XML file, but how to read the specified node value? the xml is below, for example, i want to get the value(AAA content) that named...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.