8,906
社区成员
发帖
与我相关
我的任务
分享
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 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>