你好,欢迎来到电脑编程技巧与维护杂志社! 杂志社简介广告服务读者反馈编程社区  
合订本订阅
 
 
您的位置:技术专栏 / Linux开发
使用XMLBeans绑定XML-java数据(1)
 
创建一个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)

  推荐精品文章

·2024年12月目录 
·2024年11月目录 
·2024年10月目录 
·2024年9月目录 
·2024年8月目录 
·2024年7月目录 
·2024年6月目录 
·2024年5月目录 
·2024年4月目录 
·2024年3月目录 
·2024年2月目录 
·2024年1月目录
·2023年12月目录
·2023年11月目录

  联系方式
TEL:010-82561037
Fax: 010-82561614
QQ: 100164630
Mail:gaojian@comprg.com.cn

  友情链接
 
Copyright 2001-2010, www.comprg.com.cn, All Rights Reserved
京ICP备14022230号-1,电话/传真:010-82561037 82561614 ,Mail:gaojian@comprg.com.cn
地址:北京市海淀区远大路20号宝蓝大厦E座704,邮编:100089