Xml writing quotes etc

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sagaert Johan

    Xml writing quotes etc

    Hi

    Is there some kind of method to convert strings containing " < etc to
    some form that it is allowed inside XML tags ?

    Johan




  • Martin Honnen

    #2
    Re: Xml writing quotes etc

    Sagaert Johan wrote:
    Is there some kind of method to convert strings containing " < etc to
    some form that it is allowed inside XML tags ?
    Use XmlWriter to create your XML, it does the necessary escaping for
    you. If you only want to create a text then use XmlWriterSettin gs with
    ConformanceLeve l.Fragment e.g.

    XmlWriterSettin gs settings = new XmlWriterSettin gs();
    settings.Confor manceLevel = ConformanceLeve l.Fragment;
    StringWriter writer = new StringWriter();
    using (XmlWriter xmlWriter = XmlWriter.Creat e(writer, settings))
    {
    xmlWriter.Write String("a < b && b < a");
    }
    Console.WriteLi ne(writer.ToStr ing());

    writes "a &lt; b &amp;&amp; b &lt; a".



    --

    Martin Honnen --- MVP XML

    Comment

    Working...