I'm trying to read an XML document and write out a slightly modified
version using the XmlTextWriter.
I'm basically trying to copy all the nodes exactly as they are read and
do some text manipulation on #text nodes of only certain named elements.
example
while (xmltextreader.Read())
{
if (xmltextreader.NodeType == XmlNodeType.Text)
{
string modified = xmltextreader.Value;
// manipulate string here
xmltextwriter.WriteString(modified);
}
else
{
// The dilemma is here!
xmltextwriter.WriteNode(xmltextreader, false);
}
}
The problem I face is that the WriteNode method of the XmlTextWriter
copies all of its children and this creates a problem for iterating
through all the nodes. I would like some way to pass some nodes through
to the writer with no changes.
Does anyone have a solution for performing this kind of simple
processing?
Thanks,
Pete