jfy3d(剑事)BLOG

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  37 随笔 :: 0 文章 :: 363 评论 :: 0 Trackbacks

<?xml:namespace prefix = soap />
<soap:Body>

<VERIFY xmlns="http://ormp.biz/webservices/">
<KEY>guid</KEY>
<IP>string</IP>
</VERIFY>
</soap:Body>


verify有 名为 xmlns属性的时候就会报错

附一个xml读写类
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;
    }

}

posted on 2005-10-20 22:55 剑事 阅读(1899) 评论(0)  编辑  收藏 所属分类: 小程序

只有注册用户登录后才能发表评论。


网站导航: