我用下面的鏈接中提到的變壓器代碼的XML元素及其子到XML字符串轉換越來越怪異字符在Java中
How to convert xml Element and its child nodes into String in Java?
的問題是我看到一些奇怪的字符,只有第一個元素的文本內容是明文剩下的就是一些奇怪的編碼
供您參考。這裏是代碼
Transformer transformer = TransformerFactory.newInstance().newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StreamResult result = new StreamResult(new StringWriter());
DOMSource source = new DOMSource(node);
transformer.transform(source, result);
String xmlString = result.getWriter().toString(); System.out.println(xmlString);
輸入看起來像下面
<Info ID="_65ae9406-63c9-4fd5-93a0-5ab1b5a3f3c7"
IssueInstant="2012-02-11T09:53:52.722Z" Version="2.0"
xmlns="urn:oasis:names:tc:SAML:2.0:assertion">
<Issuer>https://localhost:8080/</Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod
Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
<ds:SignatureMethod
Algorithm="http://www.w3.org/2001/04/xmldsig-more#rsa-sha256" />
<ds:Reference URI="#_65ae9406-63c9-4fd5-93a0-5ab1b5a3f3c7">
<ds:Transforms>
<ds:Transform
Algorithm="http://www.w3.org/2000/09/xmldsig#enveloped-signature" />
<ds:Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" />
</ds:Transforms>
<ds:DigestMethod Algorithm="http://www.w3.org/2001/04/xmlenc#sha256" />
<ds:DigestValue>IDHt1dgdR9k/toaocOxCVMiJhPjqRPyNSou4ywBA2YM=
</ds:DigestValue>
</ds:Reference>
</ds:SignedInfo>
<ds:SignatureValue>o5lTezATnGX+sllItfElMuabaFlpBed8wc8lAieigQ4JiIsgjIdHbg7gyyCpgk</ds:SignatureValue>
<ds:Signature></Info>
輸入是什麼樣的? –
添加輸入到問題 – user948246