Reading/altering an .xml document

  • Thread starter Thread starter Bob Robertson
  • Start date Start date
B

Bob Robertson

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
 
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
 
Back
Top