Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

What's the easiest way to read/write xml?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Andy B - 29 Mar 2008 02:43 GMT
I have this good sized xsd file I created (219 lines long). It is supposed
to be a representation of a contract a business uses. I need to know what
the best and easiest way is to create and use xml files with this schema. I
will be doing a lot of adding/changing/editing of the xml files too. I tried
to look at XmlDocument but got totally lost. Any ideas on how to overcome
this problem?
Alberto Poblacion - 29 Mar 2008 10:20 GMT
>I have this good sized xsd file I created (219 lines long). It is supposed
>to be a representation of a contract a business uses. I need to know what
>the best and easiest way is to create and use xml files with this schema. I
>will be doing a lot of adding/changing/editing of the xml files too. I
>tried to look at XmlDocument but got totally lost. Any ideas on how to
>overcome this problem?

  The easiest way is probably the following:
  - Use XSD.EXE to generate a class from your xsd file.
  - Add the class to your project. Create an instance and fill it with
data.
  - Use the XmlSerializer to serialize your class into a file. The file
will be xml and conform to the schema that you originally described in the
xsd.
Andy B - 31 Mar 2008 00:45 GMT
How do you use the XmlSerializer?

>>I have this good sized xsd file I created (219 lines long). It is supposed
>>to be a representation of a contract a business uses. I need to know what
[quoted text clipped - 10 lines]
> will be xml and conform to the schema that you originally described in the
> xsd.
Alberto Poblacion - 31 Mar 2008 08:25 GMT
> How do you use the XmlSerializer?

  Like this:

           using System.Xml.Serialization;
           using System.IO;
           ...

           TheClass myInstance = new TheClass();
           myInstance.someField = theValue;
           ...

           XmlSerializer serializer = new XmlSerializer(typeof(TheClass));
           TextWriter writer = new StreamWriter(@"C:\TEMP\TheFile.xml");
           serializer.Serialize(writer, myInstance);
           writer.Close();
Fabricio - 31 Mar 2008 14:47 GMT
On Mar 31, 4:25 am, "Alberto Poblacion" <earthling-
quitaestoparacontes...@poblacion.org> wrote:

> > How do you use the XmlSerializer?
>
[quoted text clipped - 12 lines]
>             serializer.Serialize(writer, myInstance);
>             writer.Close();

You can have another option:

Use this XSD file as a Dataset file, if possible.
Then you can work with XML files using Dataset methods (WriteXML and
ReadXML, i guess).
So, the XML file works as a table and its rows.

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.