锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲综合成人网在线观看,国产成人精品日本亚洲直接 ,亚洲精品97久久中文字幕无码http://www.tkk7.com/pdw2009/archive/2007/10/19/154222.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Fri, 19 Oct 2007 07:19:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/19/154222.htmlhttp://www.tkk7.com/pdw2009/comments/154222.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/19/154222.html#Feedback0http://www.tkk7.com/pdw2009/comments/commentRss/154222.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/154222.htmlpackage test;

import net.sf.json.*;
import java.util.*;
import domain.*;

public class JsonDemo {
    
public static void arraytojson(){
        String[] kkname
={"CCED","WPS","WORD"};
        JSONArray jr
=JSONArray.fromObject(kkname);
        System.out.println(jr);

    }
    
    
public static void list2json(){
        List
<Book> bklist=new ArrayList<Book>();
        bklist.add(
new Book("a1","b","111"));
        bklist.add(
new Book("a2","b","111"));
        bklist.add(
new Book("a3","綺鵑欽AVA","111"));
        JSONArray jr
=JSONArray.fromObject(bklist);
        System.out.println(jr);
    }
    
public static void createJson(){
        JSONArray jn
=JSONArray.fromObject("[{bookname:'JAVA紼嬪簭璁捐',isbn:'885596-99',author:'灝忎笢'}]");//寮澶村拰緇撳熬甯]
        List a=JSONArray.toList(jn, Book.class);
        Book book
=null;
        
for(Iterator it=a.iterator();it.hasNext();){
            book
=(Book)it.next();
            System.out.println(book.getAuthor()
+"-"+book.getBookname());
        }
    }
    
public static void Map2Json(){
        Map map
=new HashMap();
        map.put(
"name""灝忚4");
        map.put(
"book"new Book("K璇█紼嬪簭璁捐","鏉?/span>","55588"));
        map.put(
"shoBookName","function(){alert('嫻嬭瘯')}");
        JSONObject jo
=JSONObject.fromObject(map);
        System.out.println(jo);
    }
    
    
public static void bean2json(){
        JSONObject jo
=JSONObject.fromObject(new Book("1","3","ABCd"));
        System.out.println(jo);
    }
    
public static void json2bean(){
        JSONObject jo
=JSONObject.fromObject("{bookname:'C++紼嬪簭璁捐',isbn:'885596-989',author:'灝忎笢'}");
        Book book
=(Book)JSONObject.toBean(jo,Book.class);
        System.out.println(book.getAuthor()
+"-"+book.getBookname());
        
    }
    
public static void main(String[] args)throws Exception{
        arraytojson();
        list2json();
        createJson();
        Map2Json();
        json2bean();
    }
}


]]>
浠ュ墠鍐欑殑涓ょ瘒jdom鏂囩珷http://www.tkk7.com/pdw2009/archive/2007/10/16/153396.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Tue, 16 Oct 2007 14:53:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/16/153396.htmlhttp://www.tkk7.com/pdw2009/comments/153396.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/16/153396.html#Feedback0http://www.tkk7.com/pdw2009/comments/commentRss/153396.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/153396.html http://www.54bk.com/user1/6324/archives/2005/13861.html

]]>
Xpath 1 灝忚http://www.tkk7.com/pdw2009/archive/2007/10/16/153390.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Tue, 16 Oct 2007 14:17:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/16/153390.htmlhttp://www.tkk7.com/pdw2009/comments/153390.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/16/153390.html#Feedback0http://www.tkk7.com/pdw2009/comments/commentRss/153390.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/153390.html<?xml version="1.0" encoding="GB2312"?>

<order>
  
<item>
    
<itemNumber>C2688-67037</itemNumber>
    
<description>LCD娑叉櫠鏄劇ず鍣?/span></description>
    
<quantity>1</quantity>
    
<price>358.00</price>
  
</item>
    
<item>
    
<itemNumber>C2688-67061</itemNumber>
    
<description>闊崇</description>
    
<quantity>1</quantity>
    
<price>16.50</price>
  
</item>
    
<item>
    
<itemNumber>C2688-67010</itemNumber>
    
<description>榧犳爣</description>
    
<quantity>1</quantity>
    
<price>8.50</price>
  
</item>
</order>

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨ROOT鍏冪礌order

/order

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓殑鎵鏈塱tem鍏冪礌

/order/item

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓嬪厓绱爄tem涓殑鎵鏈塸rice鍏冪礌
/order/item/price

娉ㄩ噴錛氱敤“/”璺緞寮濮嬩唬琛ㄥ厓绱犵殑緇濆璺緞


XPath瀹氫箟鏍囧噯鍑芥暟搴?/p>

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌item涓殑鎵鏈塸rice鍊煎ぇ浜?2.60鐨勫厓绱?br /> /order/item[price>12.60]

鑺傜偣瀹氫綅錛?/p>

XML鏂囨尅鍙互琛ㄧず涓烘爲緇撴瀯鑺傜偣褰㈠紡
XPath浣跨敤妯″紡琛ㄨ揪寮忚瘑鍒玐ML鏂囨。鐨勮妭鐐廣?/p>

涓涓猉Path鐨勬ā寮忔槸浣跨敤鍙嶆枩鏉?#8220;/”鍒嗗紑瀛愬厓绱犲悕縐版弿榪拌礬寰?/p>

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓嬪厓绱爄tem涓殑鎵鏈塸rice鍏冪礌
/order/item/price

娉ㄩ噴錛氱敤“/”璺緞寮濮嬩唬琛ㄥ厓绱犵殑緇濆璺緞.

涓嶇敤“/”璺緞寮濮嬩唬琛ㄥ厓绱犵殑鐩稿璺緞

item/price

鐢?#8220;//”璺緞寮濮嬩唬琛ㄦ暣涓枃妗f弧瓚蟲潯浠剁殑鎵鏈夊厓绱?/p>

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鏂囨。涓墍鏈夌殑item鍏冪礌
//item

閫夋嫨鏈煡鍏冪礌

閫氶厤絎?nbsp;“*”鍙敤浜庨夋嫨鏈煡XML鍏冪礌

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓殑鎵鏈塱tem鍏冪礌鎵灞炵殑瀛愬厓绱?/p>

/order/item/*

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓嬫墍鏈夊瓩瀛愯緢鐨刾rice鍏冪礌
/order/*/price

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鎵鏈夊叿鏈変袱涓鍏堢殑price鍏冪礌
/*/*/price

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鏂囨。鎵鏈夊厓绱?br /> //*

閫夋嫨鍒嗘敮

浣跨敤鏂規嫭鍙穂]鍙互鎸囧畾鐗瑰畾鐨勫厓绱?/p>

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓殑絎竴涓猧tem鐨勫瓙鍏冪礌

/order/item[1]

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓殑鏈鍚庝竴涓猧tem鐨勫瓙鍏冪礌
/order/item[last()]

涓嬮潰鐨刋Path琛ㄨ揪寮忛夋嫨鍏冪礌order涓叿鏈塸rice鍏冪礌鐨刬tem鍏冪礌
/order/item[price]

涓嬮潰鐨刋Path琛ㄨ揪寮?浠庡厓绱爋rder涓夋嫨鍏鋒湁price絳変簬12.60鍏冪礌鐨刬tem鍏冪礌
/order/item[price=16.50]

涓嬮潰鐨刋Path琛ㄨ揪寮?浠庨毝灞炰簬鍏冪礌order鐨刬tem鍏冪礌涓夋嫨鍏鋒湁price絳変簬12.60鍏冪礌鐨刾rice鍏冪礌
/order/item[price=16.50]/price

閫夋嫨鍑犱釜璺緞

鍦╔Path琛ㄨ揪寮忎腑錛屼嬌鐢?nbsp;"|" 榪愮畻絎﹀彲浠ラ夋嫨鍑犱釜璺緞 銆傚疄璐ㄤ笂鏄昏緫“涓?#8221;鎿嶄綔

涓嬮潰鐨刋Path琛ㄨ揪寮?浠庨毝灞炰簬order鐨刬tem鍏冪礌涓夋嫨鎵鏈塱temNumber 鍜宒escription 鍏冪礌 
/order/item/itemNumber | /order/item/description


涓嬮潰鐨刋Path琛ㄨ揪寮?浠庢枃妗d腑閫夋嫨鎵鏈塱temNumber 鍜宒escription 鍏冪礌 
//itemNumber | //description

涓嬮潰鐨刋Path琛ㄨ揪寮?浠庢枃妗d腑閫夋嫨鎵鏈塱temNumber 錛宒escription鍜宲rice 鍏冪礌 
//itemNumber | //description | //price

涓嬮潰鐨刋Path琛ㄨ揪寮?閫夊彇灞炰簬order涓璱tem涓嬫墍鏈塱temNumber鍏冪礌鍜屼粠鏂囨。涓夋嫨鎵鏈塪escription鍏冪礌 
/order/item/itemnumber | //description

閫夋嫨灞炴?br /> 鍦╔Path涓紝鎵鏈夊睘鎬т嬌鐢ˊ鍓嶇紑

涓嬮潰鐨刋Path琛ㄨ揪寮?閫夊彇鎵鏈夊悕涓篶atalog鐨勫睘鎬?br /> //@catalog


涓嬮潰鐨刋Path琛ㄨ揪寮?閫夊彇鎵鏈夊叿鏈塩atalog灞炴х殑item鍏冪礌
//item[@catalog]

涓嬮潰鐨刋Path琛ㄨ揪寮?閫夊彇鎵鏈夊叿鏈変換浣曞睘鎬х殑item鍏冪礌
//item[@*]

涓嬮潰鐨刋Path琛ㄨ揪寮?閫夊彇鎵鏈夊叿鏈塩atalog絳変簬"parts"灞炴х殑item鍏冪礌
//item[@catalog="parts"]



]]>
XSD瀛︿範http://www.tkk7.com/pdw2009/archive/2007/10/11/152168.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Thu, 11 Oct 2007 14:45:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/11/152168.htmlhttp://www.tkk7.com/pdw2009/comments/152168.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/11/152168.html#Feedback0http://www.tkk7.com/pdw2009/comments/commentRss/152168.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/152168.htmlhttp://www.w3pop.com/learn/view/p/1/o/0/doc/schema_facets/

www.w3pop.com榪欑綉绔欎笂鏈変笌XML/HTML鐩稿叧鐨勮緇嗚祫鏂欍?br />

鍦∕yeclipse緙栧啓XSD鏂囦歡闈炲父鐨勪富娉曪紝鍙渶瑕佹妸涓嶺SD鐩稿叧鐨勫厓绱犺浣忓氨琛岋紝鍍忕紪杈慩ML涓鏍鳳紝騫朵笖鏈夋彁紺猴紝榪樺彲浠ユ牴鎹甔SD鏂囦歡寤虹珛XML鏂囦歡銆傝繖鏄竴涓殢渚垮啓鐨刋SD鏂囦歡
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.example.org/note" xmlns:tns="http://www.example.org/note">
    
<element name="note">
        
<complexType>
            
<attribute name="id" type="integer" use="required" />
            
<sequence>
                
<element  name="to" >
                    
<simpleType>
                        
<restriction base="integer">
                            
<minInclusive value="0"></minInclusive>
                            
<maxInclusive value="100"></maxInclusive>
                        
</restriction>
                    
</simpleType>
                
</element>
                
<element  name="from" type="string"/>
                
<element  name="heading" type="string"/>
                
<element  name="body" type="string"/>
                
            
</sequence>
        
</complexType>
        
    
</element>
    
</schema>


]]>
json瀛︿範http://www.tkk7.com/pdw2009/archive/2007/10/11/152049.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Thu, 11 Oct 2007 07:21:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/11/152049.htmlhttp://www.tkk7.com/pdw2009/comments/152049.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/11/152049.html#Feedback0http://www.tkk7.com/pdw2009/comments/commentRss/152049.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/152049.html xsteam鏄鐞唜ml/json鐨勫ソ宸ュ叿錛屽弬鑰僪ttp://xstream.codehaus.org/alias-tutorial.html

http://www.tkk7.com/huanghuizz/articles/142875.html     json in java鐨勪粙緇?br />
涓綃噅son瀛︿範濂芥枃
http://wangcheng.javaeye.com/blog/71343

]]>
鍒╃敤XmlBean杞繪澗璇誨啓xml(杞?http://www.tkk7.com/pdw2009/archive/2007/10/08/151058.html鏈夌尗鐩鎬即鐨勬棩瀛?/dc:creator>鏈夌尗鐩鎬即鐨勬棩瀛?/author>Mon, 08 Oct 2007 06:37:00 GMThttp://www.tkk7.com/pdw2009/archive/2007/10/08/151058.htmlhttp://www.tkk7.com/pdw2009/comments/151058.htmlhttp://www.tkk7.com/pdw2009/archive/2007/10/08/151058.html#Feedback4http://www.tkk7.com/pdw2009/comments/commentRss/151058.htmlhttp://www.tkk7.com/pdw2009/services/trackbacks/151058.html銆銆XML鍦↗ava搴旂敤紼嬪簭閲屽彉寰楄秺鏉ヨ秺閲嶈, 騫挎硾搴旂敤浜庢暟鎹瓨鍌ㄥ拰浜ゆ崲. 姣斿鎴戜滑甯歌鐨勯厤緗枃浠?閮芥槸浠ML鏂瑰紡瀛樺偍鐨? XML榪樺簲鐢ㄤ簬Java Message Service鍜學eb Services絳夋妧鏈綔涓烘暟鎹氦鎹?鍥犳,姝g‘璇誨啓XML鏂囨。鏄疿ML搴旂敤鐨勫熀紜.

銆銆Java鎻愪緵浜哠AX鍜孌OM涓ょ鏂瑰紡鐢ㄤ簬瑙f瀽XML,浣嗗嵆渚垮姝?瑕佽鍐欎竴涓◢寰鏉傜殑XML,涔熶笉鏄竴浠跺鏄撶殑浜?

銆銆浜屻乆MLBean綆浠?/p>

銆銆Hibernate宸茬粡鎴愪負鐩墠嫻佽鐨勯潰鍚慗ava鐜鐨勫璞?鍏崇郴鏁版嵁搴?/font>鏄犲皠宸ュ叿.鍦℉ibernate絳夊璞?鍏崇郴鏁版嵁搴撴槧灝勫伐鍏峰嚭鐜頒箣鍓?瀵規暟鎹簱鐨勬搷浣滄槸閫氳繃JDBC鏉ュ疄鐜扮殑,瀵規暟鎹簱鐨勪換浣曟搷浣?寮鍙戜漢鍛橀兘瑕佽嚜宸卞啓SQL璇彞鏉ュ疄鐜? 瀵硅薄/鍏崇郴鏁版嵁搴撴槧灝勫伐鍏峰嚭鐜板悗,瀵規暟鎹簱鐨勬搷浣滆漿鎴愬JavaBean鐨勬搷浣?鏋佸ぇ鏂逛究浜嗘暟鎹簱寮鍙? 鎵浠ュ鏋滄湁涓涓被浼肩殑宸ュ叿鑳藉瀹炵幇灝嗗XML鐨勮鍐欒漿鎴愬JavaBean鐨勬搷浣?灝嗕細綆鍖朮ML鐨勮鍐?鍗充嬌瀵筙ML涓嶇啛鎮夌殑寮鍙戜漢鍛樹篃鑳芥柟渚垮湴璇誨啓XML. 榪欎釜宸ュ叿灝辨槸XMLBean.

銆銆涓夈佸噯澶嘪MLBean鍜孹ML鏂囨。

銆銆XMLBean鏄疉pache鐨勪竴涓紑婧愰」鐩?鍙互浠?a snap_preview_added="spa" snap_icon_added="spa" act_suffix="" icon_trigger="false" text_trigger="true" parent_link_icon="false">http://www.apache.org涓嬭澆,鏈鏂扮殑鐗堟湰鏄?.0. 瑙e帇鍚庣洰褰曞涓?

xmlbean2.0.0
     +---bin
     +---docs
     +---lib
     +---samples
     +---schemas

銆銆鍙﹀榪樿鍑嗗涓涓猉ML鏂囨。(customers.xml),

銆銆鍦ㄦ湰鏂囩殑渚嬪瓙閲?鎴戜滑灝嗗榪欎釜鏂囨。榪涜璇誨啓鎿嶄綔. 鏂囨。婧愮爜濡備笅:

<?xml version="1.0" encoding="UTF-8"?>
<Customers>
    <customer>
            <id>1</id>
            <gender>female</gender>
            <firstname>Jessica</firstname>
            <lastname>Lim</lastname>
            <phoneNumber>1234567</phoneNumber>
            <address>
                <primaryAddress>
                        <postalCode>350106</postalCode>
                        <addressLine1>#25-1</addressLine1>
                        <addressLine2>SHINSAYAMA 2-CHOME</addressLine2>
                </primaryAddress>
                <billingAddress>
                        <receiver>Ms Danielle</receiver>
                        <postalCode>350107</postalCode>
                        <addressLine1>#167</addressLine1>
                        <addressLine2>NORTH TOWER HARBOUR CITY</addressLine2>
                </billingAddress>
            </address>
    </customer>
    <customer>
            <id>2</id>
            <gender>male</gender>
            <firstname>David</firstname>
            <lastname>Bill</lastname>
            <phoneNumber>808182</phoneNumber>
            <address>
                <primaryAddress>
                        <postalCode>319087</postalCode>
                        <addressLine1>1033 WS St.</addressLine1>
                        <addressLine2>Tima Road</addressLine2>
                </primaryAddress>
                <billingAddress>
                        <receiver>Mr William</receiver>
                        <postalCode>672993</postalCode>
                        <addressLine1>1033 WS St.</addressLine1>
                        <addressLine2>Tima Road</addressLine2>
                </billingAddress>
            </address>
    </customer>
</Customers>

銆銆榪欐槸涓涓鎴風殑鏁版嵁妯″瀷,姣忎釜瀹㈡埛閮芥湁瀹㈡埛緙栧彿(ID),濮撳悕,鎬у埆(gender),鐢佃瘽鍙風爜(phoneNumber)鍜屽湴鍧,鍏朵腑鍦板潃鏈変袱涓? 棣栬鍦板潃(PrimaryAddress)鍜屽笎鍗曞湴鍧(BillingAddress),姣忎釜鍦板潃鏈夐偖緙?鍦板潃1,鍜屽湴鍧2緇勬垚.鍏朵腑甯愬崟鍦板潃榪樻湁鏀朵歡浜?receiver).姝ゅ,榪樿鍑嗗涓涓厤緗枃浠?鏂囦歡鍚峜ustomer.xsdconfig),榪欎釜鏂囦歡鐨勪綔鐢ㄦ垜鍚庨潰浼氳,瀹冪殑鍐呭濡備笅:

<xb:config xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config">

  <xb:namespace>
    <xb:package>sample.xmlbean</xb:package>
  </xb:namespace>

</xb:config>

銆銆鍥涖乆MLBean浣跨敤姝ラ

銆銆鍜屽叾浠栭潰鍚慗ava鐜鐨勫璞?鍏崇郴鏁版嵁搴撴槧灝勫伐鍏風殑浣跨敤姝ラ涓鏍?鍦ㄦ寮忎嬌鐢╔MLBean鍓?鎴戜滑瑕佷綔涓や釜鍑嗗.

銆銆1. 鐢熸垚XML Schema鏂囦歡

銆銆浠涔堟槸XML Schema鏂囦歡? 姝e父鎯呭喌涓?姣忎釜XML鏂囦歡閮芥湁涓涓猄chema鏂囦歡,XML Schema鏂囦歡鏄竴涓猉ML鐨勭害鏉熸枃浠?瀹冨畾涔変簡XML鏂囦歡鐨勭粨鏋勫拰鍏冪礌.浠ュ強瀵瑰厓绱犲拰緇撴瀯鐨勭害鏉? 閫氫織鍦拌,濡傛灉璇碭ML鏂囦歡鏄暟鎹簱閲岀殑璁板綍,閭d箞Schema灝辨槸琛ㄧ粨鏋勫畾涔?

銆銆涓轟粈涔堥渶瑕佽繖涓枃浠? XMLBean闇瑕侀氳繃榪欎釜鏂囦歡鐭ラ亾涓涓猉ML鏂囦歡鐨勭粨鏋勪互鍙婄害鏉?姣斿鏁版嵁綾誨瀷絳? 鍒╃敤榪欎釜Schema鏂囦歡,XMLBean灝嗕細浜х敓涓緋誨垪鐩稿叧鐨凧ava Classes鏉ュ疄鐜板XML鐨勬搷浣? 鑰屼綔涓哄紑鍙戜漢鍛?鍒欐槸鍒╃敤XMLBean浜х敓鐨凧ava Classes鏉ュ畬鎴愬XML鐨勬搷浣滆屼笉闇瑕丼AX鎴朌OM.鎬庢牱浜х敓榪欎釜Schema鏂囦歡鍛? 濡傛灉瀵逛簬鐔熸倝XML鐨勫紑鍙戜漢鍛?鍙互鑷繁鏉ュ啓榪欎釜Schema鏂囦歡,瀵逛簬涓嶇啛鎮塜ML鐨勫紑鍙戜漢鍛?鍙互閫氳繃涓浜涘伐鍏鋒潵瀹屾垚.姣旇緝鏈夊悕鐨勫XMLSPY鍜孲tylus Studio閮藉彲浠ラ氳繃XML鏂囦歡鏉ョ敓鎴怱chema鏂囦歡. 鍔犲叆鎴戜滑宸茬粡鐢熸垚榪欎釜Schema鏂囦歡(customer.xsd):

       <?xml version="1.0" encoding="UTF-8"?>
       <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
                  elementFormDefault="qualified">
         <xs:element name="Customers">
           <xs:complexType>
             <xs:sequence>
               <xs:element maxOccurs="unbounded" name="customer"
                           type="customerType"/>
             </xs:sequence>
           </xs:complexType>
         </xs:element>
       <xs:complexType name="customerType">
             <xs:sequence>
               <xs:element name="id" type="xs:int"/>
               <xs:element name="gender" type="xs:string"/>
               <xs:element name="firstname" type="xs:string"/>
               <xs:element name="lastname" type="xs:string"/>
               <xs:element name="phoneNumber" type="xs:string"/>
               <xs:element name="address" type="addressType"/>
             </xs:sequence>
       </xs:complexType>
         <xs:complexType name="addressType">
             <xs:sequence>
               <xs:element name="primaryAddress" type="primaryAddressType"/>
               <xs:element name="billingAddress" type="billingAddressType"/>
             </xs:sequence>
         </xs:complexType>

         <xs:complexType name="primaryAddressType">
             <xs:sequence>
               <xs:element name="postalCode" type="xs:string"/>
               <xs:element name="addressLine1" type="xs:string"/>
               <xs:element name="addressLine2" type="xs:string"/>
             </xs:sequence>
         </xs:complexType>
         <xs:complexType name="billingAddressType">
             <xs:sequence>
                   <xs:element name="receiver" type="xs:string"/>
               <xs:element name="postalCode" type="xs:string"/>
               <xs:element name="addressLine1" type="xs:string"/>
               <xs:element name="addressLine2" type="xs:string"/>
             </xs:sequence>
         </xs:complexType>
       </xs:schema>

銆銆2. 鍒╃敤scomp鏉ョ敓鎴怞ava Classes

銆銆scomp鏄疿MLBean鎻愪緵鐨勪竴涓紪璇戝伐鍏?瀹冨湪bin鐨勭洰褰曚笅. 閫氳繃榪欎釜宸ュ叿,鎴戜滑鍙互灝嗕互涓婄殑Schema鏂囦歡鐢熸垚Java Classes.scomp鐨勮娉曞涓?-

銆銆scomp [options] [dirs]* [schemaFile.xsd]* [service.wsdl]* [config.xsdconfig]*

銆銆涓昏鍙傛暟璇存槑:

銆銆-src [dir] -- 鐢熸垚鐨凧ava Classes瀛樻斁鐩綍

銆銆-srconly -- 涓嶇紪璇慗ava Classes,涓嶄駭鐢烰ar鏂囦歡

銆銆-out [jarFileName] -- 鐢熸垚鐨凧ar鏂囦歡,緙虹渷鏄痻mltypes.jar

銆銆-compiler -- Java緙栬瘧鍣ㄧ殑璺緞,鍗矹avac鐨勪綅緗?/p>

銆銆schemaFile.xsd -- XML Schema鏂囦歡浣嶇疆

銆銆config.xsdconfig -- xsdconfig鏂囦歡鐨勪綅緗? 榪欎釜鏂囦歡涓昏鐢ㄦ潵鍒跺畾鐢熸垚鐨凧ava Class鐨勪竴浜涙枃浠跺悕瑙勫垯鍜孭ackage鐨勫悕縐?鍦ㄦ湰鏂?package鏄痵ample.xmlbean

銆銆鍦ㄦ湰鏂?鎴戞槸榪欐牱榪愯鐨?

      scomp -src build\src  -out build\customerXmlBean.jar schema\customer.xsd
             -compiler C:\jdk142_04\bin\javac customer.xsdconfig

銆銆榪欎釜鍛戒護琛岀殑鎰忔濇槸鍛婅瘔scomp鐢熸垚customerXmlBean.jar,鏀懼湪build鐩綍涓?鍚屾椂鐢熸垚婧愪唬鐮佹斁鍦╞uild\src涓? Schema鏂囦歡鏄痗ustomer.xsd,xsdconfig鏂囦歡鏄痗ustomer.xsdconfig.鍏跺疄, 鐢熸垚鐨凧ava婧愪唬鐮佹病鏈夊澶т綔鐢?鎴戜滑瑕佺殑鏄痡ar鏂囦歡.鎴戜滑鍏堢湅涓涓媌uild\src\sample\xmlbean涓嬬敓鎴愮殑Classes.

銆銆CustomersDocument.java -- 鏁翠釜XML鏂囨。鐨凧ava Class鏄犲皠

銆銆CustomerType.java -- 鑺傜偣sustomer鐨勬槧灝?/p>

銆銆AddressType.java -- 鑺傜偣address鐨勬槧灝?/p>

銆銆BillingAddressType.java -- 鑺傜偣billingAddress鐨勬槧灝?/p>

銆銆PrimaryAddressType.java -- 鑺傜偣primaryAddress鐨勬槧灝?/p>

銆銆濂戒簡,鍒版鎴戜滑鎵鏈夌殑鍑嗗宸ヤ綔宸茬粡瀹屾垚浜? 涓嬮潰灝卞紑濮嬭繘鍏ラ噸鐐?鍒╃敤鍒氭墠鐢熸垚鐨刯ar鏂囦歡璇誨啓XML.

銆銆浜斻佸埄鐢╔MLBean璇籜ML鏂囦歡

銆銆鏂板緩涓涓狫ava Project,灝哫MLBean2.0.0\lib\涓嬬殑Jar鏂囦歡鍜屽垰鎵嶆垜浠敓鎴愮殑customerXmlBean.jar鍔犲叆鍒癙roject鐨凜lassPath.

銆銆鏂板緩涓涓狫ava Class: CustomerXMLBean. 婧愮爜濡備笅:

    package com.sample.reader;

    import java.io.File;
   
    import sample.xmlbean.*;
    import org.apache.commons.beanutils.BeanUtils;
    import org.apache.xmlbeans.XmlOptions;
    public class CustomerXMLBean {
    private String filename = null;
   
    public CustomerXMLBean(String filename) {
            super();
            this.filename = filename;
    }

    public void customerReader() {
            try {
              File xmlFile = new File(filename);
              CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
              CustomerType[] customers = doc.getCustomers().getCustomerArray();
         
              for (int i = 0; i < customers.length; i++) {
                CustomerType customer = customers[i];
                println("Customer#" + i);
                println("Customer ID:" + customer.getId());
                println("First name:" + customer.getFirstname());
                println("Last name:" + customer.getLastname());
                println("Gender:" + customer.getGender());
                println("PhoneNumber:" + customer.getPhoneNumber());
                // Primary address
                PrimaryAddressType primaryAddress = customer.getAddress().getPrimaryAddress();
                println("PrimaryAddress:");
                println("PostalCode:" + primaryAddress.getPostalCode());
                println("AddressLine1:" + primaryAddress.getAddressLine1());
                println("AddressLine2:" + primaryAddress.getAddressLine2());
                // Billing address
                BillingAddressType billingAddress = customer.getAddress().getBillingAddress();
                println("BillingAddress:");
                println("Receiver:" + billingAddress.getReceiver());
                println("PostalCode:" + billingAddress.getPostalCode());
                println("AddressLine1:" + billingAddress.getAddressLine1());
                println("AddressLine2:" + billingAddress.getAddressLine2());
           
              }
            } catch (Exception ex) {
                    ex.printStackTrace();
            }
    }
    private void println(String str) {
          System.out.println(str);
    }
   public static void main(String[] args) {
      String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers.xml";
                  
     CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
                   customerXMLBean.customerReader();
    }

    }

銆銆榪愯瀹?鍙傜湅杈撳嚭緇撴灉:

       Customer#0
       Customer ID:1
       First name:Jessica
       Last name:Lim
       Gender:female
       PhoneNumber:1234567
       PrimaryAddress:
       PostalCode:350106
       AddressLine1:#25-1
       AddressLine2:SHINSAYAMA 2-CHOME
       BillingAddress:
       Receiver:Ms Danielle
       PostalCode:350107
       AddressLine1:#167
       AddressLine2:NORTH TOWER HARBOUR CITY

       Customer#1
       Customer ID:2
       First name:David
       Last name:Bill
       Gender:male
       PhoneNumber:808182
       PrimaryAddress:
       PostalCode:319087
       AddressLine1:1033 WS St.
       AddressLine2:Tima Road
       BillingAddress:
       Receiver:Mr William
       PostalCode:672993
       AddressLine1:1033 WS St.
       AddressLine2:Tima Road

銆銆鎬庝箞鏍?鏄笉鏄緢杞繪澗? XMLBean鐨勫▉鍔?

銆銆鍏佸埄鐢╔MLBean鍐橷ML鏂囦歡

銆銆鍒╃敤XMLBean鍒涘緩涓涓猉ML鏂囨。涔熸槸涓浠惰交鑰屾槗涓劇殑浜?鎴戜滑鍐嶅鍔犱竴涓狹ethod,

銆銆璇風湅涓涓嬬殑Java Class:

    public void createCustomer() {
    try {
        // Create Document
        CustomersDocument doc = CustomersDocument.Factory.newInstance();
        // Add new customer
        CustomerType customer = doc.addNewCustomers().addNewCustomer();
        // set customer info
        customer.setId(3);
        customer.setFirstname("Jessica");
        customer.setLastname("Lim");
        customer.setGender("female");
        customer.setPhoneNumber("1234567");
        // Add new address
        AddressType address = customer.addNewAddress();
        // Add new PrimaryAddress
        PrimaryAddressType primaryAddress = address.addNewPrimaryAddress();
        primaryAddress.setPostalCode("350106");
        primaryAddress.setAddressLine1("#25-1");
        primaryAddress.setAddressLine2("SHINSAYAMA 2-CHOME");

        // Add new BillingAddress
        BillingAddressType billingAddress = address.addNewBillingAddress();
        billingAddress.setReceiver("Ms Danielle");
        billingAddress.setPostalCode("350107");
        billingAddress.setAddressLine1("#167");
        billingAddress.setAddressLine2("NORTH TOWER HARBOUR CITY");

        File xmlFile = new File(filename);
        doc.save(xmlFile);
        } catch (Exception ex) {
                ex.printStackTrace();
        }

  }

銆銆淇敼main method.

    public static void main(String[] args) {
    String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
        CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
        customerXMLBean.createCustomer();
    }

銆銆榪愯,鎵撳紑customers_new.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <Customers>
    <customer>
            <id>3</id>
            <gender>female</gender>
            <firstname>Jessica</firstname>
            <lastname>Lim</lastname>
            <phoneNumber>1234567</phoneNumber>
            <address>
                    <primaryAddress>
                         <postalCode>350106</postalCode>
                         <addressLine1>#25-1</addressLine1>
                                       <addressLine2>SHINSAYAMA 2-CHOME</addressLine2>
                    </primaryAddress>
                    <billingAddress>
                        <receiver>Ms Danielle</receiver>
                        <postalCode>350107</postalCode>
                       <addressLine1>#167</addressLine1>
                       <addressLine2>NORTH TOWER HARBOUR CITY</addressLine2>
                    </billingAddress>
                    </address>
            </customer>
    </Customers>

銆銆涓冦佸埄鐢╔MLBean淇敼XML鏂囦歡

銆銆鎴戜滑鍐嶅鍔犱竴涓狹ethod:

      public void updateCustomer(int id,String lastname) {
         try {
        File xmlFile = new File(filename);
        CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
        CustomerType[] customers = doc.getCustomers().getCustomerArray();
     
        for (int i = 0; i < customers.length; i++) {
           CustomerType customer = customers[i];
          if(customer.getId()==id){
                customer.setLastname(lastname);
                break;
            }
        }
        doc.save(xmlFile);
         } catch (Exception ex) {
          ex.printStackTrace();
         }
           }

銆銆main method:

    public static void main(String[] args) {
     String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
                   
    CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
                   
    customerXMLBean.updateCustomer(3,"last");
    }

銆銆榪愯涔嬪悗,鎴戜滑灝嗕細鐪嬪埌瀹㈡埛緙栧彿涓?鐨勫鎴風殑lastname宸茬粡鏀逛負last.

銆銆鍏佸埄鐢╔MLBean鍒犻櫎涓涓猚ustomer

銆銆鍐嶅鍔犱竴涓狹ethod:

    public void deleteCustomer(int id) {
     try {
      File xmlFile = new File(filename);
     CustomersDocument doc = CustomersDocument.Factory.parse(xmlFile);
    CustomerType[] customers = doc.getCustomers().getCustomerArray();

   for (int i = 0; i < customers.length; i++) {
        CustomerType customer = customers[i];
        if(customer.getId()==id){
                        customer.setNil() ;
                        break;
               }
   }
   doc.save(xmlFile);
   } catch (Exception ex) {
        ex.printStackTrace();
        }
   }

銆銆main method:

    public static void main(String[] args) {
    String filename = "F://JavaTest//Eclipse//XMLBean//xml//customers_new.xml";
                   
    CustomerXMLBean customerXMLBean = new CustomerXMLBean(filename);
                   
    customerXMLBean.deleteCustomer(3);
    }

銆銆榪愯,鎴戜滑灝嗕細鐪嬪埌瀹㈡埛緙栧彿涓?鐨勫鎴風殑璧勬枡宸茬粡琚垹闄?

銆銆涔濄佹煡璇ML

銆銆闄や簡鏈枃鍦ㄤ互涓婅榪扮殑,鍒╃敤XMLBean鑳借交杞繪澗鏉懼畬鎴怷ML鐨勮鍐欐搷浣滃,緇撳悎XPath鍜孹Query,XMLBean榪樿兘瀹屾垚璞QL鏌ヨ鏁版嵁搴撲竴鏍鋒柟渚垮湴鏌ヨXML鏁版嵁. 鍏充簬XML鏌ヨ浠ュ強濡備綍鍒涘緩XML鏁版嵁搴? 鎴戝皢鍦ㄥ彟涓綃囨枃绔犻噷璁ㄨ.

銆銆鍗併佺粨鏉熻

銆銆XMLBean鑳藉府鍔╂垜浠交鏄撹鍐橷ML,榪欏皢鏈夊姪浜庢垜浠檷浣嶺ML鐨勫涔犲拰浣跨敤,鏈変簡榪欎釜鍩虹,寮鍙戜漢鍛樺皢涓哄涔犳洿澶氬湴XML鐩稿叧鎶鏈拰Web Services,JMS絳夊叾浠朖2EE鎶鏈墦涓嬭壇濂藉湴鍩虹.



]]>
主站蜘蛛池模板: 99爱免费观看视频在线| 亚洲精品成人区在线观看| 亚洲国产精品网站在线播放 | 亚洲国产精品VA在线观看麻豆 | 四虎精品免费永久免费视频| 亚洲色大成网站WWW久久九九 | 亚洲电影一区二区三区| 手机看黄av免费网址| 一出一进一爽一粗一大视频免费的| 亚洲视频在线观看| 亚洲国产精品日韩专区AV| 18成禁人视频免费网站| 一级毛片正片免费视频手机看| 亚洲综合久久久久久中文字幕| 亚洲国产成人久久综合区| 国产四虎免费精品视频| 中国一级特黄高清免费的大片中国一级黄色片| 亚洲精品中文字幕无乱码| 国产亚洲av人片在线观看| 色www永久免费视频| 99久久免费观看| 精品多毛少妇人妻AV免费久久| 亚洲日日做天天做日日谢| 亚洲VA中文字幕不卡无码| 国产无遮挡裸体免费视频| 亚洲一级毛片免费看| 十八禁在线观看视频播放免费| 国产成人精品日本亚洲语音| 亚洲精品亚洲人成在线麻豆| 亚洲国产一二三精品无码| 国产一级淫片a免费播放口之| 亚洲一区二区免费视频| 九九美女网站免费| 成在线人直播免费视频| 99亚洲精品卡2卡三卡4卡2卡| 亚洲av无码电影网| 亚洲精品美女久久久久9999| 亚洲精品自产拍在线观看| 亚洲色欲久久久久综合网| 免费jjzz在线播放国产| 午夜无遮挡羞羞漫画免费|