使用XMLBeans绑定XML-java数据
http://tech.ddvip.com 2007年09月02日 社区交流
内容摘要:XMLBeans提供了底层XML数据的对象视图,同时还能访问原始的XML信息集合。通过递增的解除封送xml数据和高效的访问XML 模式内置数据类型的方法,XMLBeans交付了较好的性能……
对于全局元素和属性,XMLBeans 模式编译器将分别生成名称以Document和Attribute结尾的接口。
对于在另一个元素或类型的声明中局部声明的命名类型,XMLBeans会在元素或类型接口中生成一个内部接口,形成嵌套结构。
考虑下面的employee.xsd 模式列表。
<?xml version="1.0" encoding="UTF-8"?>
<!-- This XML Schema describes Employee's
Jobstatus -->
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Employee">
<xsd:sequence>
<xsd:element name="Jobstatus">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="fullTime"/>
<xsd:enumeration value="hourly"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
因此,XMLBeans在元素Employee的接口中生成了一个内部接口Jobstatus,嵌套在了Employee接口中。
public interface Employee
extends org.apache.xmlbeans.XmlObject
{
...
public interface Jobstatus
extends org.apache.xmlbeans.XmlNMTOKEN
{
}
}
Employee类在这里扩展了org.apache.xmlbeans.XmlObject,这是所有XMLBeans类型的基础接口。所有的内置模式类型,用户定义类型和派生的模式类型都从XmlObject中继承而来。
来源:Dev2Dev 作者:Hetal C. Shah 责编:豆豆技术应用