By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,680 Members | 1,466 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,680 IT Pros & Developers. It's quick & easy.

Read & Write to XML

P: n/a
Hi,

i like to read an existing xml file which has a schema defined to it, and
then write or add data to the existing xml file using vb.net/c#.

May be this Question has been answered earlier.
Pls if anyone knows the link or example let me know

Thanks
ARvind.

Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
"Arvind P Rangan" <ar******@hotmail.com> wrote in message
news:er**************@TK2MSFTNGP12.phx.gbl...
Hi,

i like to read an existing xml file which has a schema defined to it, and
then write or add data to the existing xml file using vb.net/c#.


Try asking this question in the XML group, you will get a better response:

microsoft.public.dotnet.xml

Also see the XML namespace in the .NET Docs, there are several functional
eamples of how to do exactly what you want.
HTH,
Jeremy

Nov 20 '05 #2

P: n/a
Cor
Hi Jeremy,
i like to read an existing xml file which has a schema defined to it, and
then write or add data to the existing xml file using vb.net/c#.

Maybe it is clever to read the full question before you send such an answer.

The question is I think a full example in vb.net language code for handling
a XML file as a dataset or whatever without writing it back as a stream.

In my opinion that is not posible but I was waiting if someone could give a
better answer than me.

And because of an earlier help I could give to Arvin this morning and the
way he did give response to me, he probably knows that already and is
searching if there is something more sophisticated method.

He did has placed the same question at 13:00 GMT in the xml.dotnet. group

Cor
Nov 20 '05 #3

P: n/a
Hi Cor,
Thanks Cor
As u have mentioned i have placed the msg on Xml group and no reply till
date.
Other than someone asking me to check in archives.

I have a example given by Raju, but that does read and write a XML file but
creates a new note called <NEWDATASET> above the current RootDocument Node.

Which i don't i want the existing Schema to remain as it is.
Thanks
I can give u the Example given try it Out.
XML READ N WRITE.,
'Sample code in VB.NET

Dim ds As DataSet
ds = New DataSet
ds.ReadXmlSchema(Server.MapPath("XmlFile1.xsd"))
ds.ReadXml(Server.MapPath("XmlFile1.xml"))
Dim dv As DataView = New DataView(ds.Tables("Order"))
Dim dr As DataRowView = dv.AddNew()
dr("orderID") = "3"
dr("customerID") = "3"
dr.EndEdit()
ds.AcceptChanges()
ds.WriteXml(Server.MapPath("XmlFile1.xml"))

This does add new node.
Check it out.
Thanks
aRvind.

"Cor" <no*@non.com> wrote in message
news:3f***********************@reader21.wxs.nl...
Hi Jeremy,
i like to read an existing xml file which has a schema defined to it, and then write or add data to the existing xml file using vb.net/c#.
Maybe it is clever to read the full question before you send such an

answer.
The question is I think a full example in vb.net language code for handling a XML file as a dataset or whatever without writing it back as a stream.

In my opinion that is not posible but I was waiting if someone could give a better answer than me.

And because of an earlier help I could give to Arvin this morning and the
way he did give response to me, he probably knows that already and is
searching if there is something more sophisticated method.

He did has placed the same question at 13:00 GMT in the xml.dotnet. group

Cor

Nov 20 '05 #4

P: n/a
Hi Arvind,

You may be able to achieve what you want (without going anywhere near a
DataSet) by using the XmlDocument. But it depends...

What does your Xml look like and what do you want to add to it? And any
other info that might be useful...

Regards,
Fergus
Nov 20 '05 #5

P: n/a
Cor
Hi Arvind,
I have used that too, but I am also curious if that is the best way to do
it.

And to think about, do you really need the schema?

I did in my solution at a moment skip the schema without any problem.
What is good when you use that is first saving the original xml file before
you write it.
Because when there is an error while writing you loose all.

And to make it more complet of course I would put the reading and writing in
some
try
catch
end try

blocks

Cor

Dim ds As DataSet
ds = New DataSet
ds.ReadXmlSchema(Server.MapPath("XmlFile1.xsd"))
ds.ReadXml(Server.MapPath("XmlFile1.xml"))
Dim dv As DataView = New DataView(ds.Tables("Order"))
Dim dr As DataRowView = dv.AddNew()
dr("orderID") = "3"
dr("customerID") = "3"
dr.EndEdit()
ds.AcceptChanges()
ds.WriteXml(Server.MapPath("XmlFile1.xml"))

Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.