views:

21

answers:

1

Background
I'm reading and writing an XML document using reader and writer, with filtering logic in between the read and write operations to determine which parts read should be written back out (effectively it strips some tags out) ...

My choice of implementation currently is the following using: XmlNodeReader, XmlWriter and XmlNodeType

using System.Xml;

// Read every node
using (XmlNodeReader reader = new XmlNodeReader(xmlFragment)) {

    // But write out only nodes I want
    using (XmlWriter writer = XmlTextWriter.Create(sb, writerSettings)) {

        while (reader.Read()) {

            //... with filtering logic here to choose what is to be written.

            //  I do want to write out all entity references
            if (XmlNodeType.EntityReference == reader.NodeType)
                ; // but how do I do that here?
        }
    }
}

Problem
When I encounter an entity reference with the reader I get an empty string "" in reader.Value however it's really an   value in the XML source that has been encountered. So it's detected, but not available for me to have.

Apparently a Speciality or Edge Case:
I found the following MSDN article that indicates entity references are somewhat special while parsing, but I have been unable to use it toward a working solution. It seems sparse on details - I would prefer there be a code sample to supplement it.

+1  A: 

You may refer this link: http://msdn.microsoft.com/en-us/library/system.xml.xmlreader.name.aspx

Hope this helps!!

XmlReader.Name Property
When overridden in a derived class, gets the qualified name of the current node.node.

Priya10
Thanks. It was so simple all the time yet I couldn't see it. I pasted an excerpt from the MSDN doc into your answer so people will have it immediately available.
John K