前端之家收集整理的这篇文章主要介绍了
【XML】Jdom API解析,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
@H_
403_0@
JDOM不允许同一个节点同时被2个或多个文档相关联,要在第2个文档中使用原来老文档中的节点的话。首先需要使用detach()把这个节点分开来。
@H_
403_0@
//读取文件:
StringReader sr = new StringReader(requestXml);
InputSource is = new InputSource(sr);
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(is);
//输出元素:
Document newXmlDoc = new Document(newXmlRoot);
XMLOutputter output = new XMLOutputter();
String newXml = output.outputString(newXmlDoc);
//添加元素
root.addContent(new Element("jane"));
//获取元素:
Namespace soapenv = Namespace.getNamespace("soapenv",SOAP_URI);
Namespace put = Namespace. getNamespace("put",PUT_URI);
Element root = doc.getRootElement();
Element bodyElement = root.getChild( BODY,soapenv);
Element inbound = bodyElement.getChild("DisassembleJobcardFeedback",put).getChild( "DisassembleJobcardFeedbackInfo" );