如何将org.w3c.dom.Element xml节点对象转化成XML格式的string字符串
2011-08-02 11:27
513 查看
其中org.w3c.dom.Element xml节点的内容为
方法一:
方法二:
s的内容为
其中class="org.ofbiz.base.util.UtilValidate"为此节点的默认值
<type-validate > <fail-property resource="OrderUiLabels" property="checkhelper.select_shipping_method"/> </type-validate>
方法一:
Document document = validate.getOwnerDocument(); DOMImplementationLS domImplLS = (DOMImplementationLS) document.getImplementation(); LSSerializer serializer = domImplLS.createLSSerializer(); String str = serializer.writeToString(validate);str的内容为:
<?xml version="1.0" encoding="UTF-16"?> <type-validate> <fail-property property="checkhelper.select_shipping_destination" resource="OrderUiLabels"/> </type-validate>
方法二:
TransformerFactory transFactory = TransformerFactory.newInstance(); Transformer transformer = null; try { transformer = transFactory.newTransformer(); } catch (TransformerConfigurationException e) { e.printStackTrace(); } StringWriter buffer = new StringWriter(); transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); try { transformer.transform(new DOMSource(validate),new StreamResult(buffer)); } catch (TransformerException e) { e.printStackTrace(); } String s = buffer.toString();
s的内容为
<type-validate class="org.ofbiz.base.util.UtilValidate"> <fail-property property="checkhelper.select_shipping_destination" resource="OrderUiLabels"/> </type-validate>
其中class="org.ofbiz.base.util.UtilValidate"为此节点的默认值
相关文章推荐
- Dom节点对象转化为字符串
- js中如何把字符串转化为对象
- vb.net反射中如何将字符串转化为对象实例
- Android进步之十四:使用jackon的ObjectMapper的writeValueAsString方法可以把java对象转化成json字符串
- js数租,对象, 数组,字符串,函数,变量,int与String 型转化,String 转化为js 中内部代码,编码格式转化,<a>标签的死链接
- javascript中字符串格式json如何转化成json对象
- 如何将json字符串转化成json对象呢
- 如何将json对象转化为字符串?
- 面试题-前端-问答题-javascript中字符串格式json如何转化成json对象
- 21.如何将java类对象转化为json字符串
- js中如何把字符串转化为对象、数组示例代码
- javascript中字符串格式json如何转化成json对象
- 如何将普通字符串转化为dom节点插入页面
- JSON对象如何转化为字符串?
- vb.net反射中如何将字符串转化为对象实例
- JSON字符串如何转化成对象?
- 如何将字符串转化为Jsoup的Document 对象
- 前端js如何生成一个json对象,并转化为json字符串
- delphi中如何将string类型的字符串数据转化成byte[]字节数组类型的数据
- js中如何把字符串转化为对象、数组示例代码