Read & Write to XML

  • Thread starter Thread starter Arvind P Rangan
  • Start date Start date
A

Arvind P Rangan

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.
 
Arvind P Rangan said:
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
 
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
 
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.
 
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
 
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
 
Back
Top