<?xml:namespace prefix = soap />
<soap:Body>
<VERIFY xmlns="<KEY>guid</KEY>
<IP>string</IP>
</VERIFY>
</soap:Body>
verify有 名為 xmlns屬性的時(shí)候就會(huì)報(bào)錯(cuò)
附一個(gè)xml讀寫(xiě)類(lèi)
import org.dom4j.io.XMLWriter;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import java.io.FileWriter;
import org.dom4j.io.OutputFormat;
import java.io.File;
import org.dom4j.Document;
import org.dom4j.io.SAXReader;
public class XmlTool {
??? private String filename;
??? private SAXReader saxReader = null;
??? private Document document = null;
??? private Element cfgElement = null;
??? public XmlTool(String filename) {
??????? this.filename = filename;
??????? try {
??????????? saxReader = new SAXReader();
??????????? document = saxReader.read(new File(filename));
??????? } catch (Exception ex) {
??????????? ex.printStackTrace();
??????? }
??? }
??? public void setValue(String key, String value) {
??????? int returnValue = 0;
??????? try {
??????????? ((Element)( document.selectSingleNode(key))).setText(value);
??????? } catch (Exception ex) {
??????????? ex.printStackTrace();
??????? }
??? }
??? public String getValue(String key) {
??? int returnValue = 0;
??? try {
??????? return ((Element)( document.selectSingleNode(key))).getText();
??? } catch (Exception ex) {
??????? ex.printStackTrace();
??????? return "";
??? }
}
??? public int writeToFile() {
??????? int returnValue = 0;
??????? try {
??????????? XMLWriter writer = new XMLWriter(new FileWriter(new File(filename)));
??????????? writer.write(document);
??????????? writer.close();
??????????? returnValue = 1;
??????? } catch (Exception ex) {
??????????? ex.printStackTrace();
??????? }
??????? return returnValue;
??? }
??? public int formatXMLFile(String filename) {
??????? int returnValue = 0;
??????? try {
??????????? SAXReader saxReader = new SAXReader();
??????????? Document document = saxReader.read(new File(filename));
??????????? XMLWriter output = null;
??????????? OutputFormat format = OutputFormat.createPrettyPrint();
??????????? format.setEncoding("GBK");
??????????? output = new XMLWriter(new FileWriter(new File(filename)), format);
??????????? output.write(document);
??????????? output.close();
??????????? returnValue = 1;
??????? } catch (Exception ex) {
??????????? ex.printStackTrace();
??????? }
??????? return returnValue;
??? }
}