• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

XML Question

I have the following XML File:

<?xml version="1.0"?>
<HomescreenDesigner>
    <Settings>
        <James>Hello</James>
        <James2 />
        <James3>Hello</James3>
    </Settings>
</HomescreenDesigner>

I am trying to read it with this code:

        Dim xmlReader As New XmlTextReader(Filename)
        While (xmlReader.Read)
            If (xmlReader.NodeType = XmlNodeType.Element) Then
                Dim x As String = xmlReader.Name
                xmlReader.Read()
                MsgBox(x & vbCrLf & xmlReader.Value())
            End If
        End While

This is working as long as I dont have a empty value (<James2 />)
If I have this, it doesnt recognize the NEXT (<James3>)-Value...

Why?

Thanks
0
Ruttensoft
Asked:
Ruttensoft
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
Working fine here in 2003 and 2005?
0
 
RuttensoftAuthor Commented:
Hm yes thats true.

But instead of this formating, if I use

<?xml version="1.0"?><HomescreenDesigner><Settings><James>Hello</James><James2 /><James3>Hello</James3></Settings></HomescreenDesigner>

(Same code, just without formating)

It isnt working anymore.... why?
0
 
RuttensoftAuthor Commented:
btw. James2 is here cut, but in my file not
0
 
PaulHewsCommented:
The different spacing adds elements... the logic of reading an element, then reading the value fails because instead of reading a whitespace element, you are reading the next node.... So when you read and test the node type, you've overshot the last node...


Dim xmlReader As New XmlTextReader(Filename)

        Dim ReadFlag As Boolean = xmlReader.Read
        While ReadFlag
            Debug.WriteLine(xmlReader.NodeType)
            If (xmlReader.NodeType = XmlNodeType.Element) Then
                Dim x As String = xmlReader.Name
                xmlReader.Read()
                MsgBox(x & vbCrLf & xmlReader.Value())
            Else
                ReadFlag = xmlReader.Read()
            End If

        End While
0
 
RuttensoftAuthor Commented:
thanks man
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now