XML解析(DOM解析)
1、需要的jar包
dom4j.jar
2、需要引入的包
import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element;
xml格式
/** @param paramsXml **/ <?xml version="1.0" encoding="UTF-8"?> <request> <queryType>batch</queryType> <param> <savePath>path/to/wave/folder</savePath> <idList> ZX20130822201308221540390001001000,ZX20130821201308212047190001001000 </idList> </param> </request> /**@return **/
3、解析代码
String paramsXml;// 具有XML格式的字符串 Document document = null; document = DocumentHelper.parseText(paramsXml); /*path/to/wave/folder*/ Element savePathEle = (Element) document.selectSingleNode("//param/savePath"); /*获取元素的值,在这里获取元素savePath的值:path/to/wave/folder*/ String uploadFilePath = savePathEle.getTextTrim(); /*XXXXXXX*/ Element idListEle = (Element) document.selectSingleNode("//param/idList"); /*获取元素的值,在这里获取元素idList的值:XXXXXXr*/ String strkey = idListEle.getTextTrim();
相关推荐
Yakamoz 2020-05-26
与卿画眉共浮生 2020-10-14
xiyang 2020-08-21
XGQ 2020-07-04
Andrewjdw 2020-05-29
行吟阁 2020-05-18
88491874 2020-04-30
baijinswpu 2020-07-29
leonranri 2020-07-26
zhongliwen 2020-07-05
麋鹿麋鹿迷了路 2020-07-05
zengyu00 2020-07-05
CoderBoy 2020-06-28
whbing 2020-06-28
绝望的乐园 2020-06-27
wellfly 2020-06-26
菇星獨行 2020-06-25
草原孤狼 2020-06-25
坚持着执着 2020-06-16