472,093 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Read & Write to XML

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
5 1930
"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
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
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
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
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.

Similar topics

1 post views Thread by bdinmstig | last post: by
9 posts views Thread by Collin VanDyck | last post: by
6 posts views Thread by cj | last post: by
14 posts views Thread by Arne | last post: by

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.