加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

【XML】Jdom API解析

发布时间:2020-12-16 08:27:42 所属栏目:百科 来源:网络整理
导读:JDOM不允许同一个节点同时被2个或多个文档相关联,要在第2个文档中使用原来老文档中的节点的话。首先需要使用detach()把这个节点分开来。 //读取文件:StringReader sr = new StringReader(requestXml);InputSource is = new InputSource(sr);SAXBuilder bui

JDOM不允许同一个节点同时被2个或多个文档相关联,要在第2个文档中使用原来老文档中的节点的话。首先需要使用detach()把这个节点分开来。

//读取文件:
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" );

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读