Quantcast
Channel: MVPXML Work Item Rss Feed
Viewing all articles
Browse latest Browse all 27

Closed Issue: XPathDocumentWriter::WriteRaw escapes XML when it shouldn't

$
0
0
The WriteRaw method of the XPathDocumentWriter escapes the XML brackets < and > to &lt; and &gt; It seems that it behaves exactly as WriteString does.

Steps to reproduce:

XPathDocumentWriter xw = new XPathDocumentWriter();
xw.WriteStartElement("root");
xw.WriteRaw("<item>test</item>");
xw.WriteEndElement();
xw.Flush();
XPathNavigator xn = xw.Close();
Trace.WriteLine(xn.OuterXml);

The output is:

<root>&lt;item&gt;test&lt;item&gt;</root>

Whereas it should be:

<root><item>test</item></root>
Comments: Look in Reflector at the MS.Internal.Xml.Cache.XPathDocumentBuilder.WriteRaw implementation:

public override void WriteRaw(string data)
{
this.WriteString(data, TextBlockType.Text);
}


That's the wrapped class we're calling, it's provided by .NET and we can't change its behavior. So I guess you cannot use WriteRaw.

An alternative would be to parse the string with an XmlReader and use WriteNode instead.

Viewing all articles
Browse latest Browse all 27

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>