Editing XML Document

  • Thread starter Thread starter ameen.abdullah
  • Start date Start date
A

ameen.abdullah

Hi Guys,

I hve an application which uses xml file to store data.. Now i need to
edit/delete particular node (inner xml + attributes) in that xml file.
How can i do that?

Thanks in advance..
 
Hi Guys,

I hve an application which uses xml file to store data.. Now i need to
edit/delete particular node (inner xml + attributes) in that xml file.
How can i do that?

Thanks in advance..

It's just a text file. Open it in your favorite text editor.
 
Ameen,

An XML file says not so much, XML is a set of keywords used to by instance
define the elements and attributes in a document.

What kind of XML document do you have, the most simple question is, does it
contain only elements, than it is probably a dataset, or does it contains as
well attributes, than it is probably a document.

Cor
 
Heres a sample of xml doc which i m using:

<tables>
<table name="table1">
<columns>
<column name="col1" datatype="varchar" length="20" />
<column name="col2" datatype="int" length="2" />
<column name="col3" datatype="datetime" length="8" />
</columns>
</table>
</tables>

Now, what i need is to know how can i add a new node in columns node or
tables node, and how can i change any attribute, for eg: i need to
rename table1 to table2 or change the datatype of col1 to int through
vb.net.
 
Ameen,

This is simple, this is a datatable therefore it is just read it using
ds.readxml and then

ds.tables("table1").columns.add("col4",gettype(system.int32))

I don't think that you can change the type varchar to int32 in one time, you
can try it, than it can be
dt.Columns("col1").DataType = GetType(System.Int32)

But I don't think that will go, so you can use
\\\
ds.tables("tabel1")columns.add("colDummy",gettype(system.int32))
for each dr as datarow in ds.tables("table1")
dr("colDummy") = Cint(dr("col1"))
next
dt.Columns.("col1").remove
dt.Columns("co1Dummy").ColumnName = "col1"
////

And than write it again with WriteXML(and add the schema than to that in the
secondparameter)

This above is not really tested but typed in this message, therefore there
can be typos or whatever.

I hope this helps,

Cor
 
Back
Top