Solved

vb.NET + XML ... reader.value isn't returning anything??

Posted on 2003-10-29
2
355 Views
Last Modified: 2008-02-01
I'm trying to read an xml file in vb.net, but I'm having problem reading the value of the elements...

Here's the XML file:

--------- XML Start ---------

<?xml version='1.0'?>
   <VariableList>
      <varItem xmlns="title">This is the Title</varItem>
      <varItem xmlns="terms">These are the terms</varItem>
   </VariableList>

--------- XML End ---------


.... and Here's my vb code:


--------- VB.NET Start ---------

Imports System.XML

Dim textReader As XmlTextReader = New XmlTextReader(strSource$)

        While textReader.Read()
            Dim nType As XmlNodeType = textReader.NodeType

            If nType = XmlNodeType.Element Then
                MsgBox("Element: " & textReader.Name.ToString)
                MsgBox("Space: " & textReader.NamespaceURI.ToString)
                MsgBox("Value: " & textReader.Value.ToString)
            End If
        End While

--------- VB.NET End ---------

My problem is textReader.Value doens't return anything.... I'd like it to msgbox the "This is the Title" & "These are the terms" texts as well as the name and namespaceURI. What am I doing wrong??

Thanks,
- kisk
0
Comment
Question by:kisk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 3

Accepted Solution

by:
the-edge earned 100 total points
ID: 9648515
this is the rigth code:

        Dim textReader As XmlTextReader = New XmlTextReader(strSource$)

        While textReader.Read()
            Dim nType As XmlNodeType = textReader.NodeType
            Select Case nType
                Case Xml.XmlNodeType.Element
                    MsgBox("Element: " & textReader.Name.ToString)
                    MsgBox("Space: " & textReader.NamespaceURI.ToString)
                Case Xml.XmlNodeType.Text
                    MsgBox("Value: " & textReader.Value.ToString)
            End Select
        End While


text values are nodes of type Xml.XmlNodeType.Text

the edge
0
 

Author Comment

by:kisk
ID: 9649170
works! Thanks!!

- kisk
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question