Problems with read XML

R

René Paschold

Hello,

i write a xml file with following code:

Dim xWriter As New XmlTextWriter(SaveFileContent.FileName, _
Encoding.UTF8)

With xWriter

.Formatting = Formatting.Indented
.Indentation = 4
.WriteStartDocument()
.WriteComment("RootNote")

.WriteStartElement("article")

.WriteStartElement("headline")
.WriteString(txtHead.Text)
.WriteEndElement()

.WriteString("links")
.WriteString(txtLinks.Text)
.WriteEndElement()

.WriteStartElement("content")
.WriteString(AxDHTMLEdit1.DOM.body.innerHTML)
.WriteEndElement()

.WriteEndElement()

.WriteEndDocument()
.Close()

End With

It works great. Now the Problem. If i want to read this created XML
File and one of the nodes are emtpy than i cant read the rest. Here is
the code to read:

Dim xml As New XmlDocument
xml.Load(OpenFileContent.FileName)

txtHead.Text = _
xml.DocumentElement.ChildNodes(0).ChildNodes(0).Value

txtLinks.Text = _
xml.DocumentElement.ChildNodes(1).ChildNodes(0).Value

AxDHTMLEdit1.DOM.body.innerHTML = _
xml.DocumentElement.ChildNodes(2).ChildNodes(0).Value

What is the best way to write and read simple XML Files
with only three nodes to save program content or save
program settings (like ini file).

Greetings
René
 
C

Cor

Hi René

I don't think there is a best way.

When you have only 3 elements in a XML file with only 3 values, do it the
way that is the most simple for you. When I see your code (I never used it
that way but what I understand from it) I just would write the empty
elements with empty values.

When you want to do it without it, I think that in your example the best way
could be searching (reading) for the text element, the next value item in
the read is then your value.

But it there are so much posibilities,
Take what you fits the best with your 3 element XML file.

I hope this helps a little bit.

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top