如何将包含大原始XML的字符串格式化为格式化XML对象或字符串/流?

时间:2014-09-19 14:43:54

标签: java xml formatting

如何将原始XML字符串格式化为原始XML格式?

包含XML的字符串如下所示:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v2="http://webservice">       <soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd"><wsse:UsernameToken wsu:Id="UsernameToken-28FC7B32CCC1BB2B21141113657641136"><wsse:Username>username</wsse:Username><wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordDigest">password=</wsse:Password><wsse:Nonce EncodingType="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-soap-message-security-1.0#Base64Binary">gt/swtwet/ww==</wsse:Nonce><wsu:Created>2014-09-19T14:22:56.411Z</wsu:Created></wsse:UsernameToken></wsse:Security></soapenv:Header>       <soapenv:Body>          <v2:getThis1>             <v2:getThis12>                <v3:getThis13>                   <v3:getThis10>                      <v31:Id>31045243</v31:Id>                      <v31:getThis1222>545345</v31:getThis1222>                   </v3:getThis10>                   <v3:Number>1234124</v3:Number>                </v3:getThis14323>             </v2:getThis1343>          </v2:getThis112>       </soapenv:Body>    </soapenv:Envelope>

如何将其转换回XML格式?

1 个答案:

答案 0 :(得分:0)

我认为您要解决的问题是如何根据字符串表示法与XML对象进行比较。如果是这种情况,那么只需使用XMLUnit,这将比较xml字符串并报告差异,而不必担心格式化,将内容放入哈希映射等。