Editing xml

D

Deepak

Hi i m having trouble saving xml file .


Dim mxnode As XmlNode
Dim xElem As XmlElement
Dim xDoc As New XmlDocument()
xDoc.Load("PingAddress.xml")

Me.LoadXMLFromFile()

mxnode = xDoc.SelectSingleNode("//Item[@ID='one1']")

mxnode = mxnode.ChildNodes.Item(2) ' i need to go
to the DownTime of item one1(refer below) any

' other way

xElem = CType(mxnode, XmlElement)
xElem.InnerText = Date.Now ' here i
change the date to now but when i open the xml file its
not

changed

Heres the format of the xml file

<?xml version="1.0"?>
<Ping>
<Class Name="one">
<Item ID="one1">
<Name>one 1</Name>
<Address>10.205.4.1</Address>
<DownTime>13/02/2007 20:51:08</DownTime>
</Item>
<Item ID="Two2">
<Name>Two 2</Name>
<Address>10.205.4.1</Address>
<DownTime></DownTime>
</Item>
</Class>
</Ping>
 
D

Deepak

You must save your XML at the end.
Use xDoc.Save(); and then check your file and you'll see the updates.


I did that but it asks for the parameter of file name (there are three
others )
xdoc.save() needs a parameter

I tried
xDoc.Save("PingAddress.xml") trying to overwrite the file and it
works . Is it necessary to give the file name ?
 
S

Stephany Young

Yes.

I think that you are assuming that the XmlDocument has a relationship with
the file it was loaded from.

This is NOT the case.

When you execute xDoc.Load(<filename>), the contents of the file are parsed
and loaded into the instance of the XmlDocument. When that is complete the
XmlDocument object does not retain any knowledge about where it was 'loaded'
from.
 

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