使⽤dom4j⽣成xml报⽂
我使⽤的是dom4j创建xml报⽂
使用dom4j解析xml文件1.创建root节点
Document document = ateDocument();
Element root = ateElement("RBSPMessage");
document.setRootElement(root);
2.在root节点下添加节点
Element Version = root.addElement("Version");
Element SenderIDElement = root.addElement("SenderID");
3.为节点添加值
SenderIDElement.setText("C00-10002029");
4.为节点添加属性值
Element Security = root.addElement("Security");
Element Signature = Security.addElement("Signature");
Signature.addAttribute("Algorithm","des");
5.⽣成xml报⽂
OutputFormat format = ateCompactFormat();
format.setEncoding("UTF-8");
StringWriter writer = new StringWriter();
XMLWriter output = new XMLWriter(writer, format);
output.write(document);
writer.close();
output.close();
String();
6.返回报⽂后,获取某某节点有⼏个节点。
Document document = DocumentHelper.parseText(xml);
Element rootElement = RootElement();
List list =rootElement.selectNodes("/RBSPMessage/Method/Items/Item/Value/Row");          result = String.valueOf(list.size());

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。