使用换行符获取SignedXml输出 [英] Getting SignedXml output with line breaks

查看:111
本文介绍了使用换行符获取SignedXml输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以使SignedXml类生成在元素之间具有换行符的结果XML?

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

因为现在,这样做:

{

SignedXml ^ signedXml = gcnew SignedXml();
.....
signedXml-> ComputeSignature();

SignedXml^ signedXml = gcnew SignedXml();
.....
signedXml->ComputeSignature();

//写入文件

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

XmlTextWriter ^ xmltw = gcnew XmlTextWriter("d:\\ output xml.xml",gcnew Text :: UTF8Encoding(false));
xmlDoc-> WriteTo(xmltw);
xmltw-> Close();

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

XmlTextWriter^ xmltw = gcnew XmlTextWriter("d:\\output xml.xml", gcnew Text::UTF8Encoding(false));
xmlDoc->WriteTo(xmltw);
xmltw->Close();

//Write to file. 2nd method

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

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

}



我在一行中得到XML,就像这样:

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" />

我想要的是获得这样的易于阅读的XML :

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

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


推荐答案

尝试其他编码. UTF8可能消除了回报

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

设置 -> 编码 = 系统 :: 文本 :: 编码 :: UTF8 ;

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


这篇关于使用换行符获取SignedXml输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆