473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

XmlReadWrite

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
Nov 15 '05 #1
13 1405
Cor
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
Nov 15 '05 #2
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.

"Cor" <no*@non.com> wrote in message
news:e9**************@TK2MSFTNGP10.phx.gbl...
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

Nov 15 '05 #3
<di********@discussion.microsoft.com> wrote:
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)?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #4
Because it has XML in its name :D
I just need the easiest way to update a node in an XML file inplace.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:
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)?

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #5
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #6
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.

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
Nov 15 '05 #7
Im now looking at the DataSet way as its easier to find a specific node than
the XmlDoc I think.
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #8
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #9
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.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #10
<di********@discussion.microsoft.com> wrote:
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");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #11
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.

"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:
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");

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #12
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 15 '05 #13
Yup, but I figured out the regex anyway :D.

Its fixed ok. Its period delimited so Ill use String.replace()
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om...
<di********@discussion.microsoft.com> wrote:
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.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too

Nov 15 '05 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: | last post by:
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.