Solved

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

Posted on 2003-10-29
2
354 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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 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