创建一个XMLBean
在开始创建XMLBeans之前,需要下载并在系统中安装Apache XMLBeans 1.02。当从XMLBeans 的归档文件中提取出文件之后,将会在解压文件中看到bin目录和lib目录。随后,把bin目录放到路径中,把lib目录中的xbean.jar包放到classpath路径中。
XML 模式文件(XSD文件)创建了XMLBeans类。这些XMLBeans类能够解析所有符合XML模式的XML 实例文档。同样,通过使用这些XMLBeans类,也能够创建出实例文档。
例如,下面的weather_latlong.xsd模式列表描述了xml文档的内容,该文档包含了某个地理位置的天气、经纬度信息,这些信息全部基于zip代码。
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <!-- This XML Schema describes xml documents containing either weather details or latlong details of a location based on Zipcode Two Global elements Weather and Latlong, and one Global Attribute Zipcode are declared.--> <xsd:element name="Weather"> <xsd:complexType> <xsd:sequence> <xsd:element name="Temperature" type="xsd:float"/> <xsd:element name="Humidity" type="xsd:float"/> <xsd:element name="Visibility" type="xsd:float"/> <xsd:element name="Datetime" type="xsd:dateTime"/> </xsd:sequence> <xsd:attribute ref="Zipcode"/> </xsd:complexType> </xsd:element> <xsd:element name="Latlong"> <xsd:complexType> <xsd:sequence> <xsd:element name="Latitude" type="xsd:string"/> <xsd:element name="Longitude" type="xsd:string"/> </xsd:sequence> <xsd:attribute ref="Zipcode"/> </xsd:complexType> </xsd:element> <xsd:attribute name="Zipcode" type="xsd:string"/> </xsd:schema>
(编辑:aniston)
|