Getting SignedXml output with line breaks RRS feed

  • Question

  • Is there a way to make SignedXml class generate resulting XML with linebreaks between elements?

    Because now, doing this:


    SignedXml^ signedXml = gcnew SignedXml();

    //Write to file

    XmlDocument^ xmlDoc = gcnew XmlDocument();
    xmlDoc->PreserveWhitespace = true;
    XmlNode^ signedNode = xmlDoc->ImportNode(signedXml->GetXml(), true);

    XmlTextWriter^ xmltw = gcnew XmlTextWriter("d:\\output xml.xml", gcnew Text::UTF8Encoding(false));

    //Write to file. 2nd method

    WriteXMLFile(signedXml->GetXml(), "d:\singed xml.xml");


    void WriteXMLFile(XmlNode^ XML, String^ FilePath)
    XmlWriterSettings^ settings = gcnew XmlWriterSettings();
    settings->Encoding = System::Text::Encoding::UTF8;
    settings->OmitXmlDeclaration = true;
    settings->NewLineChars = "\n";
    XmlWriter^ xwriter = XmlWriter::Create(FilePath, settings);

    I get XML in a single line, like this:

    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#"><SignedInfo><CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />

    What I want, is to get an easily readable XML like this:

    <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
    		<CanonicalizationMethod Algorithm="http://www.w3.org/TR/2001/REC-xml-c14n-20010315" />

    • Edited by Andrius Dee Tuesday, March 17, 2015 8:04 AM
    Tuesday, March 17, 2015 8:02 AM

All replies

  • Try a different encoding.  The UTF8 is probably eliminating the returns

     settings->Encoding = System::Text::Encoding::UTF8;


    • Proposed as answer by Fred Bao Wednesday, March 18, 2015 7:20 AM
    • Marked as answer by Fred Bao Monday, March 30, 2015 9:24 AM
    • Unmarked as answer by Fred Bao Monday, March 30, 2015 12:10 PM
    Tuesday, March 17, 2015 8:09 AM