jdom解析XML问题

Wanted__杰 2014-12-03 10:42:31
本人新手,用jdom解析一段xml老是不成功,tid获取为空,求解。


public static String getElementTextFromXMLString(String xmlString,String elementName) throws JDOMException, IOException{
String tidText="";
SAXBuilder builder = new SAXBuilder();
Document doc = null;
StringReader sr = new StringReader(xmlString);
doc = builder.build(sr);
Namespace soap = Namespace.getNamespace("soap","http://schemas.xmlsoap.org/soap/envelope/");
Namespace simota = Namespace.getNamespace("simota","http://www.chinamobile.com");
Element root = doc.getRootElement();
Element body = root.getChild( "Body",soap); // 获取到Body
// Element ele = body.getChild( "PreOperationsReq",simota); //TransactionID
Element tid = body.getChild(elementName,simota);
tidText = tid.getText();
return tidText;
}

要解析的XML

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<simota:PreOperationsReq xmlns:simota="http://www.chinamobile.com">
<simota:SeqNum>20121128175631069529</simota:SeqNum>
<simota:SessionID>20121128175631027229</simota:SessionID>
<simota:SessionType>2</simota:SessionType>
<simota:TimeStamp>20121128175631</simota:TimeStamp>
<simota:CommType>4</simota:CommType>
<simota:Msisdn>13607434755</simota:Msisdn>
<simota:SEID>1200000A000112600006</simota:SEID>
<simota:AppAID>A000000333010102</simota:AppAID>
</simota:PreOperationsReq>
</soap:Body>
</soap:Envelope>
...全文
275 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Wanted__杰 2014-12-04
  • 打赏
  • 举报
回复
已解决。。。。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧