webservice接口讀取xml文件內容


xml文件我放在D:/HBJT_FILE/test.xml

xml文件內容為:

<?xml version="1.0" encoding="GB2312"?>
<RESULT>
<VALUE>  
<NO>A1234</NO>  
<ADDR>河北省</ADDR>
</VALUE>
<VALUE>  
<NO>B1234</NO>  
<ADDR>石家庄</ADDR>
</VALUE>
</RESULT>

//**byte[]轉換成String*/
BASE64Encoder enc=new BASE64Encoder();
String xmlString =enc.encode(xml);

實現類中的代碼:

//**String轉換成byte[]*/
byte[] buffer = new BASE64Decoder().decodeBuffer(xmlString);

//**將byte[]寫入xml文件*/
/*FileOutputStream out = new FileOutputStream("D:/HBJT_FILE/test.xml");
out.write(xml);
out.close(); */

SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new File("D:/HBJT_FILE/test.xml"));
Element foo = doc.getRootElement();
List allChildren = foo.getChildren();
for (int i = 0; i < allChildren.size(); i++) {
System.out.print("地址1:"+ ((Element) allChildren.get(i)).getChild("NO").getText());
System.out.println("地址2:"+ ((Element) allChildren.get(i)).getChild("ADDR").getText());


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM