锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲精品免费视频,国产香蕉尹人视频在线,99精品视频免费http://www.aygfsteel.com/stevenjohn/category/52209.html閭d簺闈掓槬鐨勫瞾鏈?/description>zh-cnWed, 15 Aug 2012 01:55:51 GMTWed, 15 Aug 2012 01:55:51 GMT60[杞澆] JDom杈撳嚭UTF-8鐨刋ML鍑虹幇涓枃涔辯爜瀹岀編瑙e喅http://www.aygfsteel.com/stevenjohn/archive/2012/08/15/385506.htmlabinabinWed, 15 Aug 2012 01:34:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/08/15/385506.htmlhttp://www.aygfsteel.com/stevenjohn/comments/385506.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/08/15/385506.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/385506.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/385506.html1錛塉DOM鏄惁鐢熸垚UTF-8鐨勬枃浠朵笌Format鏄惁璁劇疆鏃犲叧錛屽彧鏈夎緭鍑哄叾浠栧瓧絎︾紪鐮佹墠闇瑕佽緗紝瑙佷笅闈㈢殑娉ㄩ噴銆?
2錛塉DOM杈撳嚭UTF-8鏂囦歡涔辯爜鐨勬牴鏈師鍥犲茍闈炲湪JDOMAPI錛岃屾槸鍦↗DK銆?
鍏蜂綋鎻忚堪錛?
    JDOM鐨勮緭鍑虹被XMLOutputter鏈変袱涓猳utput鎺ュ彛錛岄櫎浜?jiǎn)閮藉呬h湁涓涓狣ocument鍙傛暟澶栵紝鍒嗗埆鎺ュ彈Writer鍜?OutputStream鍙傛暟銆?
    榪欑粰鎴戜滑涓涓敊瑙夛紝涓や釜鎺ュ彛鍙互浠繪剰浣跨敤銆?
    棣栧厛鎴戜滑鐢╫utput(doc,System.out)鏉ュ仛嫻嬭瘯錛屾鏃跺緱鍒頒貢鐮侊紝
      鐒跺悗鎴戜滑鏀逛負(fù)output(doc,new PrintWriter(System.out))鏉ユ祴璇曪紝杈撳嚭涓嶆槸涔辯爜錛?
      涔熷氨鏄鍦ㄦ帶鍒跺彴鐨勬椂鍊欎竴瀹氳鐢ㄤ竴涓猈riter鎺ュ彛鍖呰涓涓嬨?
     鐒跺悗鎴戜滑鐢╫utput(doc,new FileWriter(path))鏉ュ仛嫻嬭瘯錛岀粨鏋滃嵈寰楀埌涔辯爜錛?
      鐒跺悗鎴戜滑鏀逛負(fù)output(doc,new FileOutputStream(path))鏉ユ祴璇曪紝杈撳嚭涓嶆槸涔辯爜錛?
      涔熷氨鏄鍦ㄨ緭鍑烘枃浠剁殑鏃跺欎竴瀹氳鐢ㄤ竴涓狾utputStream鎺ュ彛鍖呰涓涓嬨?
     鐤簡(jiǎn)鍚э紵鍛靛懙錛屽緢鎼炵瑧鏄惂銆傜粡榪囧埌JDOM鐨勬簮鐮佷腑璋冭瘯錛屽彂鐜版病鏈変換浣曢棶棰橈紝闂鍑哄湪浜?jiǎn)JDK閲岄潰銆?
JDK鍐呯殑瀵瑰簲鎺ュ彛澶勭悊錛?
1錛塒rintWriter綾繪湁鍙傛暟涓篛utputStream鐨勬瀯閫犳柟娉曪紝鍥犳鍙互浠嶴ystem.out鍖呰鍒癙rintWriter
2錛塅ileWriter綾繪病鏈夊弬鏁頒負(fù)OutputStream鐨勬瀯閫犳柟娉曪紝鍥犳涓嶈兘浠嶧ileOutputStream鍖呰鍒?FileWriter
3錛夊鏋淧rintWriter綾葷敤浜?jiǎn)鍙傛曨C負(fù)Writer鐨勬瀯閫犳柟娉曪紙Writer瀹炵幇涓篎ileWriter錛夛紝鏈鍚庤緭鍑轟篃鏄貢鐮?
4錛夊鏋滅敤涓涓狥ileOutputStream鏉ュ寘瑁呬竴涓帶鍒跺彴杈撳嚭錛屼篃鏄貢鐮?
鍥犳錛屽浜嶫DK鍐呯殑鍚勭杈撳嚭浣撶郴錛屽悇縐岻nputStream銆丱utputStream銆乺eader鍜寃riter瑕佸厖鍒嗚璇嗭紝鍚﹀垯鏋佸鏄撳嚭鐜頒竴浜涙剰鎯充笉鍒扮殑闂銆?




abin 2012-08-15 09:34 鍙戣〃璇勮
]]>
JDOM 鐢熸垚鍜岃В鏋怷ML(浜?http://www.aygfsteel.com/stevenjohn/archive/2012/07/20/383613.htmlabinabinFri, 20 Jul 2012 09:37:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/07/20/383613.htmlhttp://www.aygfsteel.com/stevenjohn/comments/383613.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/07/20/383613.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/383613.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/383613.html//JDOM xml鐨勭敓鎴?br />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鐨勭敓鎴愮殑嫻嬭瘯浠g爜
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鐨勮В鏋愪互鍙?qiáng)瑙f瀽鐨剫箣璇曚唬鐮?br />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());
  }

 }
}


 



abin 2012-07-20 17:37 鍙戣〃璇勮
]]>
JDOM 鍒涘緩鍜岃В鏋怷ML(涓)http://www.aygfsteel.com/stevenjohn/archive/2012/07/19/383529.htmlabinabinThu, 19 Jul 2012 10:13:00 GMThttp://www.aygfsteel.com/stevenjohn/archive/2012/07/19/383529.htmlhttp://www.aygfsteel.com/stevenjohn/comments/383529.htmlhttp://www.aygfsteel.com/stevenjohn/archive/2012/07/19/383529.html#Feedback0http://www.aygfsteel.com/stevenjohn/comments/commentRss/383529.htmlhttp://www.aygfsteel.com/stevenjohn/services/trackbacks/383529.htmlpackage org.litsoft.air.unionpay;

import java.io.ByteArrayOutputStream;

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

public class CreateJdom {
 /**
  * 鐢熸垚鏀粯瀹濋渶瑕佺殑XML鏍煎紡錛岃嚜宸辨ā鎷熸祴璇曟敮浠樻帴鍙g殑寮傛榪斿洖緇撴灉
  * @return
  */
 public static String createXml(){
  Element root=new Element("notify");
  Document doc=new Document(root);
  Element trade_status=new Element("trade_status");
  trade_status.setText("TRADE_FINISHED");
  root.addContent(trade_status);
  
  Element total_fee=new Element("total_fee");
  total_fee.setText("0.90");
  root.addContent(total_fee);
  
  Element subject=new Element("subject");
  subject.setText("123465");
  root.addContent(subject);
  
  Element out_trade_no=new Element("out_trade_no");
  out_trade_no.setText("1118060201-7555");
  root.addContent(out_trade_no);
  
  Element notify_reg_time=new Element("notify_reg_time");
  notify_reg_time.setText("2010-11-1814:02:43.000");
  root.addContent(notify_reg_time);
  
  Element trade_no=new Element("trade_no");
  trade_no.setText("2010111800209965");
  root.addContent(trade_no);
  
  ByteArrayOutputStream byteRsp=new ByteArrayOutputStream();
  XMLOutputter xmlOut=new XMLOutputter();
  try {
   xmlOut.output(doc, byteRsp);
  } catch (Exception e) {
   e.printStackTrace();
   System.out.println(e.getMessage());
  }
  String temp=byteRsp.toString();
  String result=temp.substring(temp.indexOf(">")+1, temp.length());
  return result.trim();
//  return byteRsp.toString();
 }
 
 public static void main(String[] args) {
  CreateJdom jdom=new CreateJdom();
  String result=jdom.createXml();
  System.out.println(result);
 }

}











package org.litsoft.air.unionpay;

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 {
 /**
  * 瑙f瀽XMl閲岄潰鐨勬瘡涓瓧孌?br />  * @param xml
  * @return
  */
 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();
   System.out.println("root,s name="+root.getName());
   System.out.println("root,s value="+root.getValue());
   List node=root.getChildren();
   Element element=null;
   for(int i=0;i<node.size();i++){
    element=(Element)node.get(i);
    map.put(element.getName(), element.getValue());
   }
  } catch (Exception e) {
   e.printStackTrace();
  }
  return map;
 }
 
 public static void main(String[] args) {
  String xmlHeader="<"+"?"+"xml"+" version="+"\"1.0\""+" encoding="+"\"UTF-8\""+"?"+">";
  CreateJdom jdom=new CreateJdom();
  String result=jdom.createXml();
  System.out.println("xmlHeader+result="+xmlHeader+result);
  Map<String,String> map=new ParseJdom().parseXml(xmlHeader+result);
  Iterator it=map.entrySet().iterator();
  while(it.hasNext()){
   Map.Entry<String, String> entry=(Map.Entry<String, String>)it.next();
   System.out.println(entry.getKey()+" , "+entry.getValue());
  }
  
 }
}



abin 2012-07-19 18:13 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 吴江市| 曲靖市| 安岳县| 阿巴嘎旗| 施甸县| 尉犁县| 会宁县| 凤山市| 施秉县| 昌乐县| 札达县| 富裕县| 庆云县| 家居| 克东县| 高唐县| 惠来县| 察哈| 沁水县| 弋阳县| 寿宁县| 乐陵市| 南雄市| 钦州市| 海丰县| 天等县| 郸城县| 睢宁县| 连城县| 通辽市| 曲水县| 新邵县| 惠安县| 昭苏县| 恩施市| 湟源县| 威海市| 镇远县| 长兴县| 施秉县| 伊宁县|