浏览 5103 次
锁定老帖子 主题:JAXB XJC解析机制
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-05-20
如果schema定义如下 <xs:element name="PhysicalAddress"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="1"> <xs:element minOccurs="0" maxOccurs="1" ref="addressLine1" /> <xs:element minOccurs="0" maxOccurs="1" ref="addressLine2" /> <xs:element minOccurs="0" maxOccurs="1" ref="addressLine3" /> <xs:element minOccurs="0" maxOccurs="1" ref="cityName" /> <xs:element minOccurs="0" maxOccurs="1" ref="GlobalCountryCode" /> <xs:element minOccurs="0" maxOccurs="1" ref="GlobalLocationIdentifier" /> <xs:element minOccurs="0" maxOccurs="1" ref="NationalPostalCode" /> <xs:element minOccurs="0" maxOccurs="1" ref="postOfficeBoxIdentifier" /> <xs:element minOccurs="0" maxOccurs="1" ref="regionName" /> </xs:sequence> </xs:complexType> </xs:element> 生成的java类结果如下 引用 public class PhysicalAddress { protected AddressLine1 addressLine1; protected AddressLine2 addressLine2; protected AddressLine3 addressLine3; protected CityName cityName; protected String globalCountryCode; protected String globalLocationIdentifier; protected String nationalPostalCode; protected PostOfficeBoxIdentifier postOfficeBoxIdentifier; protected RegionName regionName; } 但是,如下的schema结构 <xs:element name="PartnerBusinessIdentification"> <xs:complexType> <xs:sequence minOccurs="0" maxOccurs="unbounded"> <xs:element ref="ProprietaryBusinessIdentifier" /> <xs:element ref="ProprietaryDomainIdentifier" /> <xs:element minOccurs="0" maxOccurs="1" ref="ProprietaryIdentifierAuthority" /> </xs:sequence> </xs:complexType> </xs:element> 生成的java类却如下所示,可以忽略@XMLElementRef(s)的注释暂时不用管 引用 public class PartnerBusinessIdentification { @XmlElementRefs({ @XmlElementRef(name = "ProprietaryBusinessIdentifier", type = JAXBElement.class), @XmlElementRef(name = "ProprietaryDomainIdentifier", type = JAXBElement.class), @XmlElementRef(name = "ProprietaryIdentifierAuthority", type = JAXBElement.class) }) protected List<JAXBElement<String>> proprietaryBusinessIdentifierAndProprietaryDomainIdentifierAndProprietaryIdentifierAuthority; } 我就不明白为什么不是生成以下这样的类结构呢? 引用 public class PartnerBusinessIdentification { protected ProprietaryBusinessIdentifier proprietaryBusinessIdentifier; protected ProprietaryDomainIdentifier proprietaryDomainIdentifier; protected ProprietaryIdentifierAuthority proprietaryIdentifierAuthority; } 后来比较多个类似结构的schema发现,问题应该是在<xs:sequence>上,如果它加上了maxOccurs="unbounded"属性的话,就只会在此元素对应的java类中生成一个List<?>类型的元素,而不管里面<xs:sequence>究竟有一个还是多个子元素,这样一来生成的java类就非常难处理了。我正在想对策中 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-06-26
maxOccurs="unbounded" 这个的意思是可以出现多次,所以会生成一个LIST形式!
|
|
返回顶楼 | |
发表时间:2008-08-05
我也遇到同样的问题,思考中
|
|
返回顶楼 | |
发表时间:2008-08-05
已经解决了 原因其实就是二楼兄弟说的那样 需要用一个Set来表示
|
|
返回顶楼 | |
发表时间:2008-08-06
Joo 写道 已经解决了 原因其实就是二楼兄弟说的那样 需要用一个Set来表示
能说具体一点吗?我现在对JAXB解析遇到不少问题?比如mixed="true",以及声称JAXBElement<T>等等问题 |
|
返回顶楼 | |