XmlReadWrite

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

Whats the best way to infile edit a value in an XML file? I want INI file
update functionality on a XML file.

This will come in 2.0 I was told, is this true? Until then how can I do
this easily today?


Thanks
 
Hi

In my opinion the most simple is to threat it as a dataset
dataset.readxml(path) and dataset.writexml(path)

I hope this helps,

Cor
 
I was going to try reading from the file using StreamReader.ReadToEnd() then
pass that to XmlDoc.LoadXml(s); then parse it in memory and then write it
out again.

Any reason for using that rather than just
XmlDocument.Load(StreamReader) or XmlDocument.Load(string)?
 
I was going to try reading from the file using StreamReader.ReadToEnd() then
pass that to XmlDoc.LoadXml(s); then parse it in memory and then write it
out again.
 
Because it has XML in its name :D


I just need the easiest way to update a node in an XML file inplace.
 
Because it has XML in its name :D

I just need the easiest way to update a node in an XML file inplace.

As you were doing: read it, modify the in-memory version, write it out
again. That's fine - I was just wondering why you were going to the
trouble of loading it yourself when it's easy to get the XmlDocument
class to do it.
 
I was going to try reading from the file using StreamReader.ReadToEnd()
then
pass that to XmlDoc.LoadXml(s); then parse it in memory and then write it
out again.
I think that if you are using Javascript for it that is the best method yes

A pity because with vb.net it is not more than (excluding the errortrapping)
if it is the first item in the first row roughly written
\\\
dim ds as dataset
ds.readxml(myfilepath)
ds.tables(0).rows(0)(0).item = "mychange"
ds.writexml(myfilepath)
///

Cor
 
Im now looking at the DataSet way as its easier to find a specific node than
the XmlDoc I think.
 
Im now looking at the DataSet way as its easier to find a specific node than
the XmlDoc I think.

It depends on the structure of your data. Using XPath makes it fairly
easy to find a specific node, IMO. If your data naturally fits in a
dataset, that's fine, but certainly not all hierarchical data fits
neatly in a relational table form.
 
I basically want to update a node when I give it the following lookup form
"Node1.Node2.Node3.NodeToRead"

This is how i treat the XML like an ini file.
 
I basically want to update a node when I give it the following lookup form
"Node1.Node2.Node3.NodeToRead"

This is how i treat the XML like an ini file.

Then you could use:

XmlNode node = doc.SelectSingleNode ("Node1/Node2/Node3/NodeToRead");
 
Any idea what the Regex expression to replace a "." with a "/" char?

I called th Regex ctor with "." and .Replace(.., "/") but every char gets
replaced.
 
Any idea what the Regex expression to replace a "." with a "/" char?

I called th Regex ctor with "." and .Replace(.., "/") but every char gets
replaced.

Why bother with a regular expression? Just use
String.Replace(".", "/"). Is the format of the input absolutely fixed
though? It would be nicer to just state that XPath is the query format
to start with.
 
Yup, but I figured out the regex anyway :D.

Its fixed ok. Its period delimited so Ill use String.replace()
 
Back
Top