Format XML text in a RTB

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

    Format XML text in a RTB

    Hi,
    I have a richtextbox control that displays some xml data
    either by loading from a file or by copy-paste in
    plaintext format. So, it is displayed without any
    formatting or indentation. Now, I want to display it in a
    more readable fashion. So, I want to provide an option
    like "Format Whole Document" (like the one in VS .NET).
    Is there any way to do this?

    Regards.
  • Andrew Gnenny

    #2
    Re: Format XML text in a RTB

    Hi,
    You can use the System.Xml.XmlD ocument for such purposes. For example:

    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<m ytag><mysubtag> </mysubtag></mytag>");
    doc.Save(Consol e.Out);

    This code will print given XML in formatted form:

    <?xml version="1.0" encoding="cp866 "?>
    <mytag>
    <mysubtag>
    </mysubtag>
    </mytag>

    So, you can load your XML data from the richtextbox control into the
    XmlDocument, save document into the memory stream and replace richtextbox
    control text with saved XML.

    --
    Andrew Gnenny
    pulsar2003@/no-spam/email.ru (Please remove /no-spam/ for reply)
    X-Unity Test Studio

    Bring the power of unit testing to VS .NET IDE


    "CNU" <skadiyala@hotm ail.com> wrote in message
    news:005801c395 24$9d674d20$a50 1280a@phx.gbl.. .[color=blue]
    > Hi,
    > I have a richtextbox control that displays some xml data
    > either by loading from a file or by copy-paste in
    > plaintext format. So, it is displayed without any
    > formatting or indentation. Now, I want to display it in a
    > more readable fashion. So, I want to provide an option
    > like "Format Whole Document" (like the one in VS .NET).
    > Is there any way to do this?
    >
    > Regards.[/color]


    Comment

    Working...