
Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Hello Bill,
Based on your description, your main concern here is looking for a best
means to replace all the CData Sections in your report XML document with
normal text node(with some encoding), correct?
I've tried some xpath or XSLT approach, but seems doesn't quite suit the
scenario here. One means I've got is creating a custom XmlWriter and
override the "WriteCData" method so as to do our own customized output code
logic for CData node in XML Document. here is a very simple custom writer
class demonstrate this:
===============================
public class ReplaceXMLWriter: XmlTextWriter
{
public ReplaceXMLWriter(string filename, Encoding encoding)
: base(filename, encoding)
{
}
public override void WriteCData(string text)
{
string oldText = text;
Console.WriteLine("ReplaceXMLWriter+WriteCData+oldText:{0}",
oldText);
base.WriteString(HttpUtility.HtmlEncode( text));
}
}
==================================
You can simply use your custom writer class as below:
====================
static void Run()
{
XmlDocument doc = new XmlDocument();
doc.Load(@"..\..\data.xml");
ReplaceXMLWriter rxw = new ReplaceXMLWriter("replaceddata.xml",
Encoding.UTF8);
doc.Save(rxw);
rxw.Close();
}
=========================================
Does this helps you?
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
Martin Honnen - 07 Feb 2007 13:47 GMT
> Based on your description, your main concern here is looking for a best
> means to replace all the CData Sections in your report XML document with
> normal text node(with some encoding), correct?
> here is a very simple custom writer
> class demonstrate this:
> public override void WriteCData(string text)
> {
[quoted text clipped - 6 lines]
>
> base.WriteString(HttpUtility.HtmlEncode( text));
^^^^^^^^^^^^^^^^^^^^^^
Why are you using HtmlEncode instead of simply calling WriteString? With
your approach for instance an ampersand in a CDATA section (e.g.
<![CDATA[foo & bar]]> will then be escaped twice (e.g. foo &amp;
bar)? Is that your intention? If you simply called
base.WriteString(text)
then the XmlWriter takes care of escaping that as e.g. foo & bar.

Signature
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Steven Cheng[MSFT] - 08 Feb 2007 01:47 GMT
Hi Martin,
Thanks for your good suggestion. My previous code just demonstrate that we
can do some customization as we like here :). Anyway, I did missed the
auto escaping of the WriteString method. Thanks again for your care.
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
BillAtWork - 17 Feb 2007 10:58 GMT
I'm just getting back to this issue now - thanks for your help - this looks
really good.
> Hi Martin,
>
[quoted text clipped - 10 lines]
>
> This posting is provided "AS IS" with no warranties, and confers no rights.