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 / .NET Framework / .NET SDK / September 2004

Tip: Looking for answers? Try searching our database.

Reading/altering an .xml document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Bob Robertson - 04 Sep 2004 17:42 GMT
Hey guys -

I'm fairly new to .NET and am trying to do the following: Read in one
.xml document, selectively remove and/or change certain nodes within it,
then save the results in a second document.  For instance, if I have:

<a name="a">
  <b name="b" miscattr="blah">
     <c name="c1"/>
     <c name="c2"/>
  </b>
</a>

I want to convert that into:

<a name="a">
  <b name="b" miscattr="blah">
     <c name="c3"/>
     <c name="c4"/>
     <c name="c5"/>
  </b>
</a>

Right now, I am using an XmlReader.Read() loop to parse through the
first file.  I WAS going to use XmlWriter.WriteNode(XmlReader,...) -
unfortunately, it copies all child nodes (when it hits the 'a'
everything within 'a' is copied as well).  What
classes/methods/techniques would you guys recommend for solving this
problem?

Thanks,

Bob
Joe Mayo [C# MVP] - 04 Sep 2004 18:09 GMT
Hi Bob,

Check out XmlDocument.  The tradeoff here will be that XmlDocument stores
everything in memory, which is good if your document isn't too large.  The
benefits are that it is much more flexible.  The XmlReader and XmlWriter
work with streams, which is good because you can work on extremely large
documents without wasting memory.  However, because they are forward-only
streams, you have less flexibility.

Joe
Signature

Joe Mayo, Author/Instructor
Need C#/.NET training?
visit www.mayosoftware.com
C# Tutorial - www.csharp-station.com

> Hey guys -
>
[quoted text clipped - 29 lines]
>
> Bob

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.