zoukankan      html  css  js  c++  java
  • 如何使用dom拼接xml字符串(标准方式)

    如何使用dom拼接xml字符串(标准方式) .
    package com.my.test;
    import org.dom4j.Document;
    import org.dom4j.DocumentHelper;
    import org.dom4j.Element;
    public class XmlGroup {
      /**
         * 返回applogin接口的请求xml   yes
         * @param guid
         * @param guidpwd
         * @return  String  xml信息
         */
        public static String getRquestXml(String guid, String guidpwd)
        {
           
            Document requestDoc = DocumentHelper.createDocument();
            Element root = requestDoc.addElement("message");
            Element headElement = root.addElement("head");
            headElement.addElement("guid").addText(guid);
            Element paramsElement = root.addElement("body").addElement("params");
            paramsElement.addElement("pwd").addText(guidpwd);
            paramsElement.addElement("callbackurl");
           
            return root.asXML();
        }
        
        /**
         * 返回searchemployee接口的请求xml
         * @param appid
         * @param tag
         * @param accounts

      * @return String
         */
        public String getRequestSearchEmployeeXml(String appid, String tag, String accounts)
        {
           
            Document requestDoc = DocumentHelper.createDocument();
            Element root = requestDoc.addElement("message");
            Element headElement = root.addElement("head");
            headElement.addElement("appid").addText(appid);
            headElement.addElement("tag").addText(tag);
            headElement.addElement("accounts").setText(accounts);
            Element paramsElement = root.addElement("body").addElement("params");
            paramsElement.addElement("condition").setText(accounts);
            paramsElement.addElement("pagecount").setText("20");
            paramsElement.addElement("pagenum").setText("1");
            return root.asXML();
        }
       
        public static void main(String agrs[])
        {
         //test
         String xml=getRquestXml("zhangyi","123");
         System.out.println(xml);
        
         //test
         String xml2=getRquestXml("mobile","ads324sdsa4sf3w");
         System.out.println(xml2);
        
        }
    }


     

  • 相关阅读:
    Kendo UI for jQuery电子表格控件可轻松实现Excel导出
    缩短
    google 插件 消息通知
    C#初学者的Hello World代码_艾孜尔江撰
    HTML简易的用户名密码登录页面_艾孜尔江撰
    一次性打开多个网页的工具脚本_艾孜尔江撰
    使用a标签无法跳转到指定网页的解决办法
    Flutter安装+Vscode+夜神模拟器+android SDK
    gitbook 说明
    两个模块之间项目依赖问题
  • 原文地址:https://www.cnblogs.com/qqzy168/p/3137003.html
Copyright © 2011-2022 走看看