<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    少年阿賓

    那些青春的歲月

      BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
      500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

    //JDOM xml的生成
    import java.io.ByteArrayOutputStream;

    import org.jdom2.Document;
    import org.jdom2.Element;
    import org.jdom2.output.XMLOutputter;


    public class CreateJdom {
     public static String createXml(){
      Element root=new Element("cupMobiles");
      Document doc=new Document(root);
      
      Element cupMobile=new Element("cupMobile");
      cupMobile.setAttribute("application", "UPNoCard");
      cupMobile.setAttribute("version", "1.01");
      root.addContent(cupMobile);
      
      Element transaction=new Element("transaction");
      transaction.setAttribute("type","Purchase.PMReq");
      cupMobile.addContent(transaction);
      
      Element submitTime=new Element("submitTime");
      submitTime.setText("20111207111641");
      transaction.addContent(submitTime);
      
      Element order=new Element("order");
      order.setAttribute("id", "12347733");
      transaction.addContent(order);
      
      Element merchant=new Element("merchant");
      merchant.setAttribute("id","303290047228001");
      transaction.addContent(merchant);
      
      Element accountNumber1=new Element("accountNumber1");
      accountNumber1.setText("6224130665233518");
      transaction.addContent(accountNumber1);
      
      Element transSerialNumber=new Element("transSerialNumber");
      transSerialNumber.setText("201162");
      transaction.addContent(transSerialNumber);
      
      Element billAmount =new Element("billAmount");
      billAmount.setAttribute("currency","156");
      billAmount.setText("000000030231");
      transaction.addContent(billAmount);
      
      Element settleDate=new Element("settleDate");
      settleDate.setText("20111208");
      transaction.addContent(settleDate);
      
      ByteArrayOutputStream byteRsp=new ByteArrayOutputStream();
      XMLOutputter xmlOut=new XMLOutputter();
      try {
       xmlOut.output(doc, byteRsp);
      } catch (Exception e) {
       e.printStackTrace();
       System.out.println(e.getMessage());
      }
      return byteRsp.toString();
     }
     
     
     public static void main(String[] args) {
      
     }
    }



    //JDOM xml的生成的測試代碼
    import junit.framework.TestCase;

    import org.junit.After;
    import org.junit.Before;
    import org.junit.Test;

    public class CreateJdomTest extends TestCase{
     @Before
     public void setUp(){}
     @After
     public void tearDown(){}
     @Test
     public void testCreateJdom(){
      String result=new CreateJdom().createXml();
      System.out.println(result);
     }
    }






    //JDOM xml的解析以及解析的測試代碼
    import java.io.StringReader;
    import java.util.Collections;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.List;
    import java.util.Map;

    import org.jdom2.Document;
    import org.jdom2.Element;
    import org.jdom2.input.SAXBuilder;
    import org.xml.sax.InputSource;

    public class ParseJdom {
     public static Map<String, String> parseXml(String xml) {
      Map<String, String> map = Collections
        .synchronizedMap(new HashMap<String, String>());
      StringReader reader = new StringReader(xml);
      InputSource source = new InputSource(reader);
      SAXBuilder sax = new SAXBuilder();
      try {
       Document doc = sax.build(source);
       Element root = doc.getRootElement();
    //   map.put(root.getName(), root.getValue());
    //   System.out.println("root=" + root.getName());
    //   System.out.println("root,s value=" + root.getValue());
       
       Element cupMobile = null;
       cupMobile = root.getChild("cupMobile");
    //   map.put(cupMobile.getName(), cupMobile.getValue());
       String application=cupMobile.getAttributeValue("application");
       map.put("application", application);
       String version=cupMobile.getAttributeValue("version");
       map.put("version", version);

       
       Element transaction = null;
       transaction = cupMobile.getChild("transaction");
    //   map.put(transaction.getName(), transaction.getValue());
       String type=transaction.getAttributeValue("type");
       map.put("type", type);

       Element submitTime = null;
       submitTime = transaction.getChild("submitTime");
       map.put(submitTime.getName(), submitTime.getValue());
       
       Element order  = null;
       order = transaction.getChild("order");
    //   map.put(order.getName(), order.getValue());
       String orderId=order.getAttributeValue("id");
       map.put("orderId", orderId);

       Element merchant  = null;
       merchant = transaction.getChild("merchant");
    //   map.put(merchant.getName(), merchant.getValue());
       String merchantId=merchant.getAttributeValue("id");
       map.put("merchantId", merchantId);

       Element accountNumber1  = null;
       accountNumber1 = transaction.getChild("accountNumber1");
       map.put(accountNumber1.getName(), accountNumber1.getValue());
       
       Element transSerialNumber  = null;
       transSerialNumber = transaction.getChild("transSerialNumber");
       map.put(transSerialNumber.getName(), transSerialNumber.getValue());
       
       Element billAmount  = null;
       billAmount = transaction.getChild("billAmount");
       map.put(billAmount.getName(), billAmount.getValue());
       String currency=billAmount.getAttributeValue("currency");
       map.put("currency", currency);
       
       Element settleDate  = null;
       settleDate = transaction.getChild("settleDate");
       map.put(settleDate.getName(), settleDate.getValue());
       
       
       
      } catch (Exception e) {
       e.printStackTrace();
       System.out.println(e.getMessage());
      }
      return map;
     }

     public static void main(String[] args) {
      String xml = new CreateJdom().createXml();
      Map<String, String> map = new ParseJdom().parseXml(xml);
      Iterator it = map.entrySet().iterator();
      while (it.hasNext()) {
       Map.Entry<String, String> entry = (Map.Entry<String, String>) it
         .next();
       System.out.println("key=" + entry.getKey());
       System.out.println("Value=" + entry.getValue());
      }

     }
    }


     

    posted on 2012-07-20 17:37 abin 閱讀(2082) 評論(0)  編輯  收藏 所屬分類: JDOM

    只有注冊用戶登錄后才能發(fā)表評論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲AV无码一区二区三区牛牛| 免费无码作爱视频| 久久精品国产亚洲av品善| 一区二区三区免费视频观看| 无人在线观看免费高清| 免费视频成人片在线观看| 最新免费jlzzjlzz在线播放| 亚洲人成人网站在线观看| 亚洲免费一级视频| 国产伦精品一区二区免费| 成人免费网站在线观看| 2020久久精品亚洲热综合一本| 久久免费线看线看| 亚洲精品人成无码中文毛片| 高清免费久久午夜精品| 永久在线毛片免费观看| 亚洲成人在线免费观看| 国产精品免费一区二区三区四区| 免费在线观看你懂的| 亚洲码和欧洲码一码二码三码| 亚欧人成精品免费观看| 久久精品国产精品亚洲色婷婷| 有码人妻在线免费看片| 亚洲人JIZZ日本人| 美女巨胸喷奶水视频www免费| 国产专区一va亚洲v天堂| 亚洲AV成人无码天堂| 小草在线看片免费人成视久网| 亚洲成av人片不卡无码| 免费观看国产小粉嫩喷水| 亚洲国产aⅴ成人精品无吗| 国产v精品成人免费视频400条| 亚洲人成电影福利在线播放| 免费播放在线日本感人片| 亚洲国产精品成人久久久| 免费国内精品久久久久影院| 国产拍拍拍无码视频免费| 国产精品高清视亚洲一区二区 | 日本免费一区尤物| 亚洲欧洲专线一区| 亚洲欧洲美洲无码精品VA|