简易的JAVA处理XML工具:J2XB

原文地址:http://os.ajava.org/category/xml/%E7%AE%80%E6%98%93%E7%9A%84java%E5%A4%84%E7%90%86xml%E5%B7%A5%E5%85%B7%EF%BC%9Aj2xb/

 


一、J2XB 简介
J2XB是Java2XmlBinding的简称,提供JAVA与XML的集成功能,它可以把XML文件绑定到JAVA类型。J2XB有什么特别的地方?那就是没有难懂的JAVA代码,只用简单的代码就可以实现XML的创建、写入、读取等功能。



二、J2XB的功能特点:
1.使用JAVA代码生成XML Schema(包括Schema的所有属性)
    * XML验证(约束面, 如minLength、patterns等).
    * 置换组(允许原先定义好的元素被其他元素所替换).
    * 完全控制XML文档结构,包括Java的扁平结构和XML元素组。
    * 支持所有XML类型.
    * XML联合类型.
    * XML列表类型.

2.绑定JAVA对象到XML
    *不要求继承同一个超类。
    *无需实现任何接口。
    *不要求有一个默认的构造器。
    *若工厂提供了,不要求有一个公共的构造。
    *完全支持工厂(如静态工厂、实例工厂等)。
    *支持Java集合类型(Set, List, Array)。

3.完全支持继承
    * 映射为置换组.
    * 通过置换组完整地、精确地创建XML Schema。
    * 映射对象类型和数量到XML联合类型.

4.支持XML解析器完整的解耦,支持Apache Axiom 和 Apache XmlBeans两个默认有效的解析器,当然也可以添加其他的解析器。

三、J2XB 1.1版本的新特点
    * 新注释:MORegisterPropertyEditors 和 MORegisterPropertyEditor
    * 新注释:MOSeeAlso
    * 新注释:MOWebParam
    * 默认映射到内置Exception类型,可选择性映射到stack trace
    * J2XB的核心变化是,集成了Axis2 - 更多资料可看J2XB Axis2 module的介绍
    * 多条漏洞修复


四、J2XB实例
1.下载J2XB。
2.把J2XB添加到classpath中。
3.在你的JAVA代码中添加注释。最基本的是,你需要在任何一个需要映射的类中添加MOPersistentBean注释。
@MOPersistentBean(xmlName = "HelloWorld")
public class HelloWorld {

        private String name;
        private String type;
        private int classID;

        @MOProperty()
        public String getName() {
                return name;
        }

        public void setName(String name) {
                this.name = name;
        }

        @MOProperty()
        public int getClassID() {
                return classID;
        }

        public void setClassID(int classID) {
                this.classID = classID;
        }

        @MOProperty()
        public String getType() {
                return type;
        }

        public void setType(String type) {
                this.type = type;
        }

}

4.创建binding model.
  MoXmlBindingModel xmlBindingModel = new MoXmlBindingModel();
  xmlBindingModel.addBean(HelloWorld.class);
  xmlBindingModel.addBean(MyClass2.class);

5.产生XML Schema
xmlBindingModel.generateSchemas(new File("some folder"));

6.选择一个XML解析器。目前J2XB支持 Apache Axiom和Apache XmlBeans.你可以使用Axiom persister。
  // using the Axiom persister
  XmlPersister xmlPersister = new XmlAxiomPersister();

 或者使用XmlBeans persister (在上面的第五步需要预编译产生schemas和产生的类加入到classpath里).

7.写XML
  HelloWorld myInstance = new HelloWorld();
  xmlPersister.save(xmlBindingModel, myInstance, "c:/temp/myFile.xml");

8.读XML
  HelloWorld myInstance = xmlPersister.load(xmlBindingModel, HelloWorld.class, "c:/temp/myFile.xml");


五、下载
官方下载地址:http://sourceforge.net/project/showfiles.php?group_id=228363


六、参考资料:
主站地址:http://j2xb.sourceforge.net/index.html
API文档地址:http://j2xb.sourceforge.net/apidocs/index.html
XML Schema简介:http://ajava.org/course/xml/8548.html

七、结束语
本文对J2XB作了简单的介绍,由于本人水平有限,如发现有错误纰漏,请指正。
联系方式:
网站:http://ajava.org
QQ:76662116
EM:chinesedocument@gamil.com

八、作者简介
mark,ajava.org站长,软件工程师,从事多年软件开发,曾开发多个市级、省级、国家级软件。

Cmdline: com.ss.android.ugc.aweme pid: 15609, tid: 16014, name: #LogReaper >>> com.ss.android.ugc.aweme <<< uid: 10318 tagged_addr_ctrl: 0000000000000001 (PR_TAGGED_ADDR_ENABLE) pac_enabled_keys: 000000000000000f (PR_PAC_APIAKEY, PR_PAC_APIBKEY, PR_PAC_APDAKEY, PR_PAC_APDBKEY) signal 6 (SIGABRT), code -1 (SI_QUEUE), fault addr -------- Abort message: 'GC tried to mark invalid reference 0x26e8168 ref=0x26e8168 klass=0x0 <invalid address> space=main space (region space) 0x2000000-0xa2000000 card=111 adjacent_ram=0000000000000000 0000000000000000 0000000000000000 0000000000000000 |0000000000000000 0000000000000000 0000000000000000 0000000000000000 holder=0x47480b8 klass=0xa7a916e8(java.lang.Class<java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock>) space=main space (region space) 0x2000000-0xa2000000 card=0 adjacent_ram=08e3f5f000000000 01000000023016e8 0000001e05044408 0000000000000000 |10000000a7a916e8 00000000026e8168 00000000a79fd4c0 7474680800000009 field_offset=8 name=sync reference addr adjacent_ram=01000000023016e8 0000001e05044408 0000000000000000 10000000a7a916e8 |00000000026e8168 00000000a79fd4c0 7474680800000009 000000312e312f70 0xb4000071da2b7000 main space (region space) 0x2000000-0xa2000000 0xb4000071da2b7308 region space live bitmap[begin=0x2000000,end=0xa2000000] 0xb4000071da2b7308 region space live bitmap[begin=0x2000000,end=0xa2000000] 0xb4000071da240900 SpaceTypeImageSpace begin=0xa79a4000,end=0xa7b5ab88,size=1754KB,name="/system/framework/ocomp/arm64/boot.art"] 0xb4000071da240988 imagespace /system/framework/ocomp/arm64/boot.art live-bitmap 0[begin=0xa79a4000,end=0xa7b5ac00] 0xb4000071da240988 imagespace /system/framework/ocomp/arm64/boot.art live-bitmap 0[begin=0xa79a4000,end=0xa7b5ac00] 0xb4000071da242400 SpaceTypeImageSpace begin=0xa7d9c000,end=0xa7dc2700,size=153KB,name="/system/framework/ocomp/arm64/boot-core-libart.art"] 0xb4000071da242488 imagespace /system/framework/ocomp/arm64/boot-core-libart.art live-bitmap 1[begin=0xa7d9c000,end=0xa7dc2800] 0xb4000071da242488 imagespace /system/framework/ocomp/arm64/boot-core-libart.art live-bitmap 1[begin=0xa7d9c000,end=0xa7dc2800] 0xb4000071da242580 SpaceTypeImageSpace begin=0xa7df8000,end=0xa7e0e028,size=88KB,name="/system/framework/ocomp/arm64/boot-okhttp.art"] 0xb4000071da242608 imagespace /system/framework/ocomp/arm64/boot-okhttp.art live-bitmap 2[begin=0xa7df8000,end=0xa7e0e400] 0xb4000071da242608 imagespace /system/framework/ocomp/arm64/boot-okhttp.art live-bitmap 2[begin=0xa7df8000,end=0xa7e0e400] 0xb4000071da242700 SpaceTypeImageSpace begin=0xa7e2c000,end=0xa7e64998,size=226KB,name="/system/framework/ocomp/arm64/boot-bouncycastle.art"] 0xb4000071da242788 imagespace /system/framework/ocomp/arm64/boot-bouncycastle.art live-bitmap 3[begin=0xa7e2c000,end=0xa7e64c00] 0xb4000071da242788 imagespace /system/framework/ocomp/arm64/boot-bouncycastle.art live-bitmap 3[begin=0xa7e2c000,end=0xa7e64c00] 0xb4000071da242880 SpaceTypeImageSpace begin=0xa7e98000,end=0xa7eaadd8,size=75KB,name="/system/framework/ocomp/arm64/boot-apache-xml.art"] 0xb4000071da242908 imagespace /system/framework/ocomp/arm64/boot-apache-xml.art live-bitmap 4[begin=0xa7e98000,end=0xa7eab000] 0xb4000071da242908 imagespace /system/framework/ocomp/arm64/boot-apache-xml.art live-bitmap 4[begin=0xa7e98000,end=0xa7eab000] 0xb4000071da242a00 SpaceTypeImageSpace begin=0xa7ec0000,end=0xa8813fe0,size=9551KB,name="/system/framework/ocomp/arm64/boot-framework.art"] 0xb4000071da242a88 imagespace /system/framework/ocomp/arm64/boot-framework.art live-bitmap 5[begin=0xa7ec0000,end=0xa8814000] 0xb4000071da242a88 imagespace /system/framework/ocomp/arm64/boot-framework.art live-bitmap 5[begin=0xa7ec0000,end=0xa8814000] 0xb4000071da242b80 SpaceTypeImageSpace begin=0xa93dc000,end=0xa93dc310,size=784B,name="/system/framework/ocomp/arm64/boot-framework-graphics.art"] 0xb4000071da242c08 imagespace /system/framework/ocomp/arm64/boot-framework-graphics.art live-bitmap 6[begin=0xa93dc000,end=0xa93dc400] 0xb4000071da242c08 imagespace /system/framework/ocomp/arm64/boot-framework-graphics.art live-bitmap 6[begin=0xa93dc000,end=0xa93dc400] 0xb4000071da242d00 SpaceTypeImageSpace begin=0xa93e0000,end=0xa93f00f0,size=64KB,name="/system/framework/ocomp/arm64/boot-framework-location.art"] 0xb4000071da242d88 imagespace /system/framework/ocomp/arm64/boot-framework-location.art live-bitmap 7[begin=0xa93e0000,end=0xa93f0400] 0xb4000071da242d88 imagespace /system/framework/ocomp/arm64/boot-framework-location.art live-bitmap 7[begin=0xa93e0000,end=0xa93f0400] 0xb4000071da242e80 SpaceTypeImageSpace begin=0xa940c000,end=0xa9427710,size=109KB,name="/system/framework/ocomp/arm64/boot-ext.art"] 0xb4000071da242f08 imagespace /system/framework/ocomp/arm64/boot-ext.art live-bitmap 8[begin=0xa940c000,end=0xa9427800] 0xb4000071da242f08 imagespace /system/framework/ocomp/arm64/boot-ext.art live-bitmap 8[begin=0xa940c000,end=0xa9427800] 0xb4000071da27e000 SpaceTypeImageSpace begin=0xa943c000,end=0xa9513980,size=862KB,name="/system/framework/ocomp/arm64/boot-telephony-common.art"] 0xb4000071da27e088 imagespace /system/framework/ocomp/arm64/boot-telephony-common.art live-bitmap 9[begin=0xa943c000,end=0xa9513c00] 0xb4000071da27e088 imagespace /system/framework/ocomp/arm64/boot-telephony-common.art live-bitmap 9[begin=0xa943c000,end=0xa9513c00] 0xb4000071da27e180 SpaceTypeImageSpace begin=0xa9664000,end=0xa96a85f0,size=273KB,name="/system/framework/ocomp/arm64/boot-voip-common.art"] 0xb4000071da27e208 imagespace /system/framework/ocomp/arm64/boot-voip-common.art live-bitmap 10[begin=0xa9664000,end=0xa96a8800] 0xb4000071da27e208 imagespace /system/framework/ocomp/arm64/boot-voip-common.art live-bitmap 10[begin=0xa9664000,end=0xa96a8800] 0xb4000071da27e300 SpaceTypeImageSpace begin=0xa970c000,end=0xa9729fc0,size=119KB,name="/system/framework/ocomp/arm64/boot-ims-common.art"] 0xb4000071da27e388 imagespace /system/framework/ocomp/arm64/boot-ims-common.art live-bitmap 11[begin=0xa970c000,end=0xa972a000] 0xb4000071da27e388 imagespace /system/framework/ocomp/arm64/boot-ims-common.art live-bitmap 11[begin=0xa970c000,end=0xa972a000] 0xb4000071da27e480 SpaceTypeImageSpace begin=0xa975c000,end=0xa9760318,size=16KB,name="/system/framework/ocomp/arm64/boot-framework-ondeviceintelligence-platform.art"] 0xb4000071da27e508 imagespace /system/framework/ocomp/arm64/boot-framework-ondeviceintelligence-platform.art live-bitmap 12[begin=0xa975c000,end=0xa9760400] 0xb4000071da27e508 imagespace /system/framework/ocomp/arm64/boot-framework-ondeviceintelligence-platform.art live-bitmap 12[begin=0xa975c000,end=0xa9760400] 0xb4000071da27e600 SpaceTypeImageSpace begin=0xa9768000,end=0xa97821c0,size=104KB,name="/system/framework/ocomp/arm64/boot-framework-nfc.art"] 0xb4000071da27e688 imagespace /system/framework/ocomp/arm64/boot-framework-nfc.art live-bitmap 13[begin=0xa9768000,end=0xa9782400] 0xb4000071da27e688 imagespace /system/framework/ocomp/arm64/boot-framework-nfc.art live-bitmap 13[begin=0xa9768000,end=0xa9782400] 0xb4000071da27e780 SpaceTypeImageSpace begin=0xa97b0000,end=0xa98fc330,size=1328KB,name="/system/framework/ocomp/arm64/boot-oplus-framework.art"] 0xb4000071da27e808 imagespace /system/framework/ocomp/arm64/boot-oplus-framework.art live-bitmap 14[begin=0xa97b0000,end=0xa98fc400] 0xb4000071da27e808 imagespace /system/framework/ocomp/arm64/boot-oplus-framework.art live-bitmap 14[begin=0xa97b0000,end=0xa98fc400] 0xb4000071da27e900 SpaceTypeImageSpace begin=0xa9ac8000,end=0xa9ac81e0,size=480B,name="/system/framework/ocomp/arm64/boot-com.android.fmradio.art"] 0xb4000071da27e988 imagespace /system/framework/ocomp/arm64/boot-com.android.fmradio.art live-bitmap 15[begin=0xa9ac8000,end=0xa9ac8400] 0xb4000071da27e988 imagespace /system/framework/ocomp/arm64/boot-com.android.fmradio.art live-bitmap 15[begin=0xa9ac8000,end=0xa9ac8400] 0xb4000071da27ea80 SpaceTypeImageSpace begin=0xa9acc000,end=0xa9acc1f8,size=504B,name="/system/framework/ocomp/arm64/boot-subsystem-framework.art"] 0xb4000071da27eb08 imagespace /system/framework/ocomp/arm64/boot-subsystem-framework.art live-bitmap 16[begin=0xa9acc000,end=0xa9acc400] 0xb4000071da27eb08 imagespace /system/framework/ocomp/arm64/boot-subsystem-framework.art live-bitmap 16[begin=0xa9acc000,end=0xa9acc400] 0xb4000071da27ec00 SpaceTypeImageSpace begin=0xa9ad0000,end=0xa9ad80d0,size=32KB,name="/system/framework/ocomp/arm64/boot-mediatek-common.art"] 0xb4000071da27ec88 imagespace /system/framework/ocomp/arm64/boot-mediatek-common.art live-bitmap 17[begin=0xa9ad0000,end=0xa9ad8400] 0xb4000071da27ec88 imagespace /system/framework/ocomp/arm64/boot-mediatek-common.art live-bitmap 17[begin=0xa9ad0000,end=0xa9ad8400] 0xb4000071da27ed80 SpaceTypeImageSpace begin=0xa9ae0000,end=0xa9b205d8,size=257KB,name="/system/framework/ocomp/arm64/boot-mediatek-framework.art"] 0xb4000071da27ee08 imagespace /system/framework/ocomp/arm64/boot-mediatek-framework.art live-bitmap 18[begin=0xa9ae0000,end=0xa9b20800] 0xb4000071da27ee08 imagespace /system/framework/ocomp/arm64/boot-mediatek-framework.art live-bitmap 18[begin=0xa9ae0000,end=0xa9b20800] 0xb4000071da27ef00 SpaceTypeImageSpace begin=0xa9b4c000,end=0xa9b4faf8,size=14KB,name="/system/framework/ocomp/arm64/boot-mediatek-ims-common.art"] 0xb4000071da27ef88 imagespace /system/framework/ocomp/arm64/boot-mediatek-ims-common.art live-bitmap 19[begin=0xa9b4c000,end=0xa9b4fc00] 0xb4000071da27ef88 imagespace /system/framework/ocomp/arm64/boot-mediatek-ims-common.art live-bitmap 19[begin=0xa9b4c000,end=0xa9b4fc00] 0xb4000071da27f080 SpaceTypeImageSpace begin=0xa9b54000,end=0xa9b5b580,size=29KB,name="/system/framework/ocomp/arm64/boot-mediatek-ims-base.art"] 0xb4000071da27f108 imagespace /system/framework/ocomp/arm64/boot-mediatek-ims-base.art live-bitmap 20[begin=0xa9b54000,end=0xa9b5b800] 0xb4000071da27f108 imagespace /system/framework/ocomp/arm64/boot-mediatek-ims-base.art live-bitmap 20[begin=0xa9b54000,end=0xa9b5b800] 0xb4000071da27f200 SpaceTypeImageSpace begin=0xa9b64000,end=0xa9c2d868,size=806KB,name="/system/framework/ocomp/arm64/boot-core-icu4j.art"] 0xb4000071da27f288 imagespace /system/framework/ocomp/arm64/boot-core-icu4j.art live-bitmap 21[begin=0xa9b64000,end=0xa9c2dc00] 0xb4000071da27f288 imagespace /system/framework/ocomp/arm64/boot-core-icu4j.art live-bitmap 21[begin=0xa9b64000,end=0xa9c2dc00] 0xb4000071da27f380 SpaceTypeImageSpace begin=0xaba60000,end=0xabde30c8,size=3596KB,name="/system/framework/ocomp/arm64/boot-framework-adservices.art"] 0xb4000071da27f408 imagespace /system/framework/ocomp/arm64/boot-framework-adservices.art live-bitmap 22[begin=0xaba60000,end=0xabde3400] 0xb4000071da27f408 imagespace /system/framework/ocomp/arm64/boot-framework-adservices.art live-bitmap 22[begin=0xaba60000,end=0xabde3400] 0xb4000071acbd3880 SpaceTypeZygoteSpace begin=0xac284000,end=0xac9d5000,size=7492KB,name="Zygote space"] 0xb4000071acbd3910 allocspace zygote / non moving space live-bitmap 0[begin=0xac284000,end=0xac9d5000] 0xb4000071acbd3990 allocspace zygote / non moving space live-bitmap 0[begin=0xac284000,end=0xac9d5000] 0xb4000071acbd3600 SpaceTypeMallocSpace begin=0xac9d5000,end=0xacb89000,limit=0xb0284000,size=1744KB,capacity=56MB,non_growth_limit_capacity=56MB,name="non moving space"] 0xb4000071acbd3690 allocspace non moving space live-bitmap 1[begin=0xac9d5000,end=0xb0284000] 0xb4000071acbd3710 allocspace non moving space live-bitmap 1[begin=0xac9d5000,end=0xb0284000] 0xb4000071da273f00 free list large object space - begin: 0xb0284000 end: 0xc8284000 Large object at address: 0xb0284000 of length 32768 bytes Large object at address: 0xb028c000 of length 20480 bytes Free block at address: 0xb0291000 of length 12288 bytes Large object at address: 0xb0294000 of length 49152 bytes Large object at address: 0xb02a0000 of length 65536 bytes Large object at address: 0xb02b0000 of length 28672 bytes Large object at address: 0xb02b7000 of length 16384 bytes Large object at address: 0xb02bb000 of length 16384 bytes Free block at address: 0xb02bf000 of length 8192 bytes Large object at address: 0xb02c1000 of length 49152 bytes Large object at address: 0xb02cd000 of length 49152 bytes Large object at address: 0xb02d9000 of length 32768 bytes Large object at address: 0xb02e1000 of length 32768 bytes Free block at address: 0xb02e9000 of length 8192 bytes Large object at address: 0xb02eb000 of length 16384 bytes Large object at address: 0xb02ef000 of length 20480 bytes Large object at address: 0xb02f4000 of length 20480 bytes Large object at address: 0xb02f9000 of length 57344 bytes Large object at address: 0xb0307000 of length 32768 bytes Free block at address: 0xb030f000 of length 4096 bytes Large object at address: 0xb0310000 of length 20480 bytes Free block at address: 0xb0315000 of length 4096 bytes Large object at address: 0xb0316000 of length 24576 bytes Large object at address: 0xb031c000 of length 28672 bytes Large object at address: 0xb0323000 of length 32768 bytes Large object at address: 0xb032b000 of length 16384 bytes Large object at address: 0xb032f000 of length 57344 bytes Free block at address: 0xb033d000 of length 24576 bytes Large object at address: 0xb0343000 of length 16384 bytes Large object at address: 0xb0347000 of length 20480 bytes Large object at address: 0xb034c000 of length 16384 bytes Large object at address: 0xb0350000 of length 16384 bytes Large object at address: 0xb0354000 of length 16384 bytes Large object at address: 0xb0358000 of length 16384 bytes Large object at address: 0xb035c000 of length 483328 bytes Large object at address: 0xb03d2000 of length 16384 bytes Large object at address: 0xb03d6000 of length 28672 bytes Large object at address: 0xb03dd000 of length 57344 bytes Large object at address: 0xb03eb000 of length 16384 bytes Large object at address: 0xb03ef000 of length 110592 bytes Large object at address: 0xb040a000 of length 28672 bytes Free block at address: 0xb0411000 of length 20480 bytes Large object at address: 0xb0416000 of length 28672 bytes Large object at address: 0xb041d000 of length 28672 bytes Large object at address: 0xb0424000 of length 20480 bytes Large object at address: 0xb0429000 of length 28672 bytes Large object at address: 0xb0430000 of length 24576 bytes Large object at address: 0xb0436000 of length 28672 bytes Large object at address: 0xb043d000 of length 28672 bytes Large object at address: 0xb0444000 of length 28672 bytes Large object at address: 0xb044b000 of length 24576 bytes Large object at address: 0xb0451000 of length 24576 bytes Large object at address: 0xb0457000 of length 32768 bytes Large object at address: 0xb045f000 of length 24576 bytes Free block at address: 0xb0465000 of length 4096 bytes Large object at address: 0xb0466000 of length 24576 bytes Large object at address: 0xb046c000 of length 303104 bytes Large object at address: 0xb04b6000 of length 32768 bytes Large object at address: 0xb04be000 of length 24576 bytes Large object at address: 0xb04c4000 of length 24576 bytes Large object at address: 0xb04ca000 of length 32768 bytes Free block at address: 0xb04d2000 of length 4096 bytes Large object at address: 0xb04d3000 of length 16384 bytes Large object at address: 0xb04d7000 of length 16384 bytes Large object at address: 0xb04db000 of length 28672 bytes Large object at address: 0xb04e2000 of length 16384 bytes Large object at address: 0xb04e6000 of length 2002944 bytes Large object at address: 0xb06cf000 of length 200704 bytes Free block at address: 0xb0700000 of length 233472 bytes Large object at address: 0xb0739000 of length 28672 bytes Large object at address: 0xb0740000 of length 24576 bytes Free block at address: 0xb0746000 of length 16384 bytes Large object at address: 0xb074a000 of length 126976 bytes Large object at address: 0xb0769000 of length 20480 bytes Large object at address: 0xb076e000 of length 32768 bytes Free block at address: 0xb0776000 of length 8192 bytes Large object at address: 0xb0778000 of length 16384 bytes Free block at address: 0xb077c000 of length 4096 bytes Large object at address: 0xb077d000 of length 32768 bytes Large object at address: 0xb0785000 of length 24576 bytes Large object at address: 0xb078b000 of length 20480 bytes Large object at address: 0xb0790000 of length 24576 bytes Large object at address: 0xb0796000 of length 28672 bytes Large object at address: 0xb079d000 of length 81920 bytes Large object at address: 0xb07b1000 of length 57344 bytes Large object at address: 0xb07bf000 of length 16384 bytes Large object at address: 0xb07c3000 of length 204800 bytes Large object at address: 0xb07f5000 of length 16384 bytes Large object at address: 0xb07f9000 of length 24576 bytes Large object at address: 0xb07ff000 of length 16384 bytes Large object at address: 0xb0803000 of length 24576 bytes Large object at address: 0xb0809000 of length 16384 bytes Large object at address: 0xb080d000 of length 20480 bytes Large object at address: 0xb0812000 of length 53248 bytes Large object at address: 0xb081f000 of length 36864 bytes Large object at address: 0xb0828000 of length 16384 bytes Large object at address: 0xb082c000 of length 24576 bytes Large object at address: 0xb0832000 of length 28672 bytes Free block at address: 0xb0839000 of length 12288 bytes Large object at address: 0xb083c000 of length 32768 bytes Large object at address: 0xb0844000 of length 20480 bytes Large object at address: 0xb0849000 of length 32768 bytes Large object at address: 0xb0851000 of length 32768 bytes Large object at address: 0xb0859000 of length 40960 bytes Large object at address: 0xb0863000 of length 28672 bytes Large object at address: 0xb086a000 of length 163840 bytes Large object at address: 0xb0892000 of length 352256 bytes
最新发布
08-30
package com.hexiang.utils; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; /** * 本类是专门解析XML文件的,主要用于为系统读取自己的配置文件时提供最方便的解析操作 * @author HX * */ public class XmlManager { /** * 得到某节点下某个属性的值 * @param element 要获取属性的节点 * @param attributeName 要取值的属性名称 * @return 要获取的属性的值 * @author HX_2010-01-12 */ public static String getAttribute( Element element, String attributeName ) { return element.getAttribute( attributeName ); } /** * 获取指定节点下的文本 * @param element 要获取文本的节点 * @return 指定节点下的文本 * @author HX_2010-01-12 */ public static String getText( Element element ) { return element.getFirstChild().getNodeValue(); } /** * 解析某个xml文件,并在内存中创建DOM树 * @param xmlFile 要解析的XML文件 * @return 解析某个配置文件后的Document * @throws Exception xml文件不存在 */ public static Document parse( String xmlFile ) throws Exception { // 绑定XML文件,建造DOM树 DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); Document domTree = db.parse( xmlFile ); return domTree; } /** * 获得某节点下的某个子节点(指定子节点名称,和某个属性的值) * 即获取parentElement下名字叫childName,并且属性attributeName的值为attributeValue的子结点 * @param parentElement 要获取子节点的那个父节点 * @param childName 要获取的子节点名称 * @param attributeName 要指定的属性名称 * @param attributeValue 要指定的属性的值 * @return 符合条件的子节点 * @throws Exception 子结点不存在或有多个符合条件的子节点 * @author HX_2008-12-01 */ public static Element getChildElement( Element parentElement, String childName, String attributeName, String attributeValue ) throws Exception { NodeList list = parentElement.getElementsByTagName( childName ); int count = 0; Element curElement = null; for ( int i = 0 ; i < list.getLength() ; i ++ ) { Element child = ( Element )list.item( i ); String value = child.getAttribute( attributeName ); if ( true == value.equals( attributeValue ) ) { curElement =
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值