?
Solved

XML Question

Posted on 2007-08-09
5
Medium Priority
?
161 Views
Last Modified: 2010-04-23
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
Comment
Question by:Ruttensoft
  • 3
  • 2
5 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 19665329
Working fine here in 2003 and 2005?
0
 

Author Comment

by:Ruttensoft
ID: 19665550
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
 

Author Comment

by:Ruttensoft
ID: 19665641
btw. James2 is here cut, but in my file not
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 2000 total points
ID: 19665840
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
 

Author Comment

by:Ruttensoft
ID: 19666001
thanks man
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 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