public static void main(String arge[]) {
String strPath="<apijsuss><apiheader><userid>0004</userid><userpassword>DJU+WcACSrE9qu9oAix0ohZSvBOlGR6GjUThFwIy2XQ=</userpassword><apiid>4430240</apiid><applicationid>443</applicationid><apiversion>1.0.0</apiversion><operationtime>20111130170441</operationtime><businessdate>20111130</businessdate><paymentdate/><requestjournal>1234567890987654321</requestjournal><responsejournal/><responsetype>E</responsetype><responsecode>UUS20003</responsecode><responsemessage>用户密码错误</responsemessage><securitylevel>1</securitylevel><signaturemethod>MD5</signaturemethod></apiheader><apicontent><production><merchid/><businesid>2011040217385722</businesid><serviceid>0004</serviceid><contractid>2011113016465515</contractid><contracteffdate/><contractexpdate/><productionid>2011113016465515</productionid><productionname>三点一刻奶茶</productionname><productiontype>01</productiontype><verifyflag>Y</verifyflag><verifysettleflag>S1</verifysettleflag><productionefftime>20111207000000</productionefftime><productionexptime>20111212000000</productionexptime><verifyexpdate>20111220</verifyexpdate><cityid>2011102814361750</cityid><cityname>淮安</cityname><cityprofitrate>65</cityprofitrate><agentid>1</agentid><agentname>上海薪火</agentname><agentprofitrate>35</agentprofitrate><price>170</price><settlementprice>170</settlementprice><settleperiod>2</settleperiod><settledate1/><settlerate1>60</settlerate1><settledate2/><settlerate2>40</settlerate2><settledate3/><settlerate3/></production></apicontent><apisecurity><signaturevalue>9a3aacfc304484cb2161062397f05b1f</signaturevalue></apisecurity></apijsuss>";
try
{
SAXBuilder builder = new SAXBuilder();
Reader rd = new StringReader(strPath);
Document doc = builder.build(rd);
Element root = doc.getRootElement();
System.out.println(root.getChildren("apijsuss"));
}catch(Exception ex)
{
ex.printStackTrace();
}
//这里如何取responsemessage 的这个值
}
------解决方案--------------------
- Java code
String responsemessage = root.getChild("apiheader").getChild("responsemessage").getText(); System.out.println(responsemessage);