473,513 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
Jul 21 '05 #1
13 1421
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
Jul 21 '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

Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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

Jul 21 '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
Jul 21 '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

Jul 21 '05 #14

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

Similar topics

13
1409
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
7171
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
7388
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,...
1
7111
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7539
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5692
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3240
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3228
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
807
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.