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()); }