- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我是 Jaxb 新手,这是我第一次使用它。我有一个 xml,我希望将其转换为我现有的对象。我成功地使用了简单的属性和元素,但是对于集合,我得到了空集合。
我想生成一个带有 xml 的版权持有者实例。我创建了一个 http post 方法来发送 xml 并使用注释对其进行解码。为了生成 post 方法,我使用了一个名为 Poster 的 Firefox 插件。来自 CopyrightHolder 的所有集合都无法加载。 (PS:契约(Contract)集合未映射)。对 post 方法的调用有效,创建了版权所有者,但所有集合为空。我想我遗漏了一些注释。
感谢任何帮助。
类(class):
版权持有人联系人:
@XmlRootElement(name="Contact", namespace="http://www.example.org/common")
//@XmlType(name="Contact", namespace="http://www.example.org/common")
public class CopyHolderContacts implements Contact, Serializable {
private Long idContact;
private CopyrightHolder copyrightHolder;
private String name;
private String email;
private String office;
private String work;
private String mobile;
private Boolean notify;
public CopyHolderContacts() {
}
public CopyHolderContacts(CopyrightHolder copyrightHolder, String name, String email) {
this.copyrightHolder = copyrightHolder;
this.name = name;
this.email = email;
}
public CopyHolderContacts( CopyrightHolder copyrightHolder, String name, String email, String office,
String work, String mobile, Boolean notify ) {
this.copyrightHolder = copyrightHolder;
this.name = name;
this.email = email;
this.office = office;
this.work = work;
this.mobile = mobile;
this.notify = notify;
}
@XmlTransient
public Long getIdContact() {
return this.idContact;
}
public void setIdContact( Long idContact ) {
this.idContact = idContact;
}
@XmlTransient
public CopyrightHolder getCopyrightHolder() {
return this.copyrightHolder;
}
public void setCopyrightHolder(CopyrightHolder copyrightHolder) {
this.copyrightHolder = copyrightHolder;
}
@XmlAttribute
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
@XmlAttribute
public String getEmail() {
return this.email;
}
public void setEmail(String email) {
this.email = email;
}
@XmlAttribute(name="phoneOffice")
public String getOffice() {
return this.office;
}
public void setOffice(String office) {
this.office = office;
}
@XmlAttribute(name="phoneWork")
public String getWork() {
return this.work;
}
public void setWork(String work) {
this.work = work;
}
@XmlAttribute(name="phoneMobile")
public String getMobile() {
return this.mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
@XmlAttribute
public Boolean getNotify() {
return this.notify;
}
public void setNotify(Boolean notify) {
this.notify = notify;
}
}
版权持有人:
import static javax.persistence.GenerationType.SEQUENCE;
import java.io.Serializable;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;
import javax.persistence.Transient;
import javax.persistence.UniqueConstraint;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.bind.annotation.XmlTransient;
import org.hibernate.annotations.Cascade;
@XmlRootElement(name="CopyrightHolder", namespace="http://www.example.org/copyrightholder")
@XmlSeeAlso(CopyHolderContacts.class)
@Entity
public class CopyrightHolder implements Serializable {
private Long idCopyrightHolder;
private String name;
private String address;
private String affiliation;
private Set<CopyHolderDocuments> copyHolderDocuments = new HashSet<CopyHolderDocuments>( 0 );
private Set<CopyHolderContacts> copyHolderContacts = new HashSet<CopyHolderContacts>( 0 );
private Set<Contract> contracts = new HashSet<Contract>( 0 );
private Set<CustomLicFieldValue> copyHolderCustomLicFieldValues = new HashSet<CustomLicFieldValue>( 0 );
private List<XMLCustomField> customFields;
public CopyrightHolder() {
}
public CopyrightHolder( String name, String address, String affiliation ) {
this.name = name;
this.address = address;
this.affiliation = affiliation;
}
public CopyrightHolder( String name, String address, String affiliation,
Set<CopyHolderDocuments> copyHolderDocuments, Set<CopyHolderContacts> copyHolderContacts,
Set<Contract> contracts, Set<CustomLicFieldValue> customLicFieldValues ) {
this.name = name;
this.address = address;
this.affiliation = affiliation;
this.copyHolderDocuments = copyHolderDocuments;
this.copyHolderContacts = copyHolderContacts;
this.contracts = contracts;
this.copyHolderCustomLicFieldValues = customLicFieldValues;
}
@XmlTransient
public Long getIdCopyrightHolder() {
return this.idCopyrightHolder;
}
public void setIdCopyrightHolder( Long idCopyrightholder ) {
this.idCopyrightHolder = idCopyrightholder;
}
@XmlAttribute
public String getName() {
return this.name;
}
public void setName( String name ) {
this.name = name;
}
@XmlElement(name="Address", namespace="http://www.example.org/copyrightholder")
public String getAddress() {
return this.address;
}
public void setAddress( String address ) {
this.address = address;
}
@XmlAttribute
public String getAffiliation() {
return this.affiliation;
}
public void setAffiliation( String affiliation ) {
this.affiliation = affiliation;
}
@XmlElementWrapper(name="Documents")
@XmlElement(name="Document")
public Set<CopyHolderDocuments> getCopyHolderDocuments() {
return this.copyHolderDocuments;
}
public void setCopyHolderDocuments( Set<CopyHolderDocuments> copyHolderDocuments ) {
this.copyHolderDocuments = copyHolderDocuments;
}
@XmlElementWrapper(name="Contacts", namespace="http://www.example.org/common")
@javax.xml.bind.annotation.XmlElement(name="Contact", namespace="http://www.example.org/common")
public Set<CopyHolderContacts> getCopyHolderContacts() {
return this.copyHolderContacts;
}
public void setCopyHolderContacts( Set<CopyHolderContacts> copyHolderContacts ) {
this.copyHolderContacts = copyHolderContacts;
}
@XmlTransient
public Set<Contract> getContracts() {
return this.contracts;
}
public void setContracts( Set<Contract> contracts ) {
this.contracts = contracts;
}
@XmlTransient
public Set<CustomLicFieldValue> getCopyHolderCustomLicFieldValues() {
return this.copyHolderCustomLicFieldValues;
}
public void setCopyHolderCustomLicFieldValues( Set<CustomLicFieldValue> customLicFieldValues ) {
this.copyHolderCustomLicFieldValues = customLicFieldValues;
}
@Transient
@XmlElementWrapper(name="custom-fields")
@XmlElement(name="custom-field")
public List<XMLCustomField> getCustomFields() {
return customFields;
}
public void setCustomFields(List<XMLCustomField> customFields) {
this.customFields = customFields;
}
}
我发送的 XML:
<?xml version="1.0" encoding="UTF-8"?>
<CopyrightHolder affiliation="ingest" name="ingest" xmlns="http://www.example.org/copyrightholder" xmlns:cm="http://www.example.org/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.example.org/copyrightholder copyrightholder2.xsd ">
<Address>Address</Address>
<Contacts>
<cm:Contact email="ingest2@ingest.com" name="ingest" notify="true" phoneMobile="" phoneOffice="" phoneWork=""/>
</Contacts>
<Documents>
<cm:FilePath>cm:FilePath</cm:FilePath>
</Documents>
<CustomFields>
<cm:CustomField name="ingest" order="0" required="false" type="Alphanumeric" value=""/>
</CustomFields>
</CopyrightHolder>
XSD:
common.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/common" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:cm="http://www.example.org/common">
<xsd:complexType name="contact">
<xsd:sequence></xsd:sequence>
<xsd:attribute name="name" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"></xsd:minLength>
<xsd:maxLength value="50"></xsd:maxLength>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="email" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:pattern value="\w+@\w+"></xsd:pattern>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="phoneOffice" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="phoneWork" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="phoneMobile" type="xsd:string" use="optional"></xsd:attribute>
<xsd:attribute name="notify" type="xsd:boolean" use="optional"></xsd:attribute>
</xsd:complexType>
<xsd:complexType name="documents">
<xsd:sequence>
<xsd:element name="FilePath" type="xsd:string" minOccurs="1" maxOccurs="unbounded">
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="custom-field">
<xsd:sequence></xsd:sequence>
<xsd:attribute name="name" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"></xsd:minLength>
<xsd:maxLength value="50"></xsd:maxLength>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="required" type="xsd:boolean" use="optional" default="false">
</xsd:attribute>
<xsd:attribute name="type" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:enumeration value="Alphanumeric"></xsd:enumeration>
<xsd:enumeration value="Date"></xsd:enumeration>
<xsd:enumeration value="Number"></xsd:enumeration>
<xsd:enumeration value="Percentage"></xsd:enumeration>
<xsd:enumeration value="Text"></xsd:enumeration>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="order" type="xsd:int" use="optional"></xsd:attribute>
<xsd:attribute name="value" type="xsd:string" use="required"></xsd:attribute>
</xsd:complexType>
<xsd:complexType name="contacts">
<xsd:sequence>
<xsd:element name="Contact" type="cm:contact" minOccurs="1" maxOccurs="unbounded"></xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="custom-fields">
<xsd:sequence>
<xsd:element name="CustomField" minOccurs="1" maxOccurs="unbounded" type="cm:custom-field"></xsd:element>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
版权持有人.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema targetNamespace="http://www.example.org/copyrightholder" elementFormDefault="qualified" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.example.org/copyrightholder" xmlns:cm="http://www.example.org/common">
<xsd:import namespace="http://www.example.org/common" schemaLocation="common.xsd"></xsd:import>
<xsd:complexType name="CopyrightHolder">
<xsd:sequence>
<xsd:element name="Address" type="xsd:string" minOccurs="1" maxOccurs="1"></xsd:element>
<xsd:element name="Contacts" type="cm:contacts" minOccurs="0" maxOccurs="1">
</xsd:element>
<xsd:element name="Documents" type="cm:documents" minOccurs="0" maxOccurs="1">
</xsd:element>
<xsd:element name="CustomFields" type="cm:custom-fields" minOccurs="0" maxOccurs="1">
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"></xsd:minLength>
<xsd:maxLength value="50"></xsd:maxLength>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="affiliation" use="required">
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:minLength value="1"></xsd:minLength>
<xsd:maxLength value="50"></xsd:maxLength>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
<xsd:element name="CopyrightHolder" type="CopyrightHolder"></xsd:element>
</xsd:schema>
最佳答案
你的命名空间搞乱了。例如:
@XmlElementWrapper(name="Contacts", namespace="http://www.example.org/common")
@javax.xml.bind.annotation.XmlElement(name="Contact", namespace="http://www.example.org/common")
public Set<CopyHolderContacts> getCopyHolderContacts() {
return this.copyHolderContacts;
}
在 XML 文档中,Contacts
包装元素具有 http://www.example.org/copyrightholder
命名空间。
尝试将其更改为
@XmlElementWrapper(name="Contacts", namespace="http://www.example.org/copyrightholder")
@XmlElement(name="Contact", namespace="http://www.example.org/common")
其他集合也类似。
关于java - Jaxb 解码 : not getting my collection elements,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10284502/
下面两个CSS选择器有什么区别? 来自解释here ,它们听起来一样吗? div p{} 选择div元素内的所有p元素 div > p{} 选择父级为 div 元素的所有 p 元素。 最佳答案 区别在
我需要怎么做: 目前,事实证明: 我更喜欢它看起来像: 最佳答案 有了这些空行,看起来您的 select 语句是(正确地)选择您
用替换元素是否有效至 .在这种情况下,我想要, 这样我就可以在...中附加验证数据。这也可以从 中实现吗?或 等等? 最佳答案 标签没有 而且不需要一个。同样适用于 和 .您可以将验证数据作为
我刚刚发现了 Angular 1.2.1 的一个奇怪问题,在 this fiddle 中进行了演示。 (在 IE、FF 和 Chrome 中测试):如果我创建一个非常简单的模板化指令,它无法像 那样
我正在尝试使用 Jsoup 迭代 java 中的两个元素,但是,我收到运行时异常错误。看来我无法将nodes.Element 的类型转换为element.Element。 非常感谢您的帮助,谢谢。 代
假设我的文档中有一组元素,它们是单个对象的子元素。这些元素中的每一个都使用不同的参数注册一个新的事件监听器。如果我丢弃父对象,是否需要手动取消注册所有 eventListener?或者浏览器是否跟踪所
我不应该在我的应用程序中使用 jQuery,但我有一个场景,我需要元素的偏移量,而不是使用 $(element).offset() 我已经使用了 angular.element(element).of
我是TS的新手,我想知道为什么我在以下代码中遇到类型错误(简化):。错误在`{iconMap[名称]}中:。“元素隐式具有‘any’类型,因为‘字符串’类型的表达式不能用于索引类型‘{Categori
我是TS的新手,我想知道为什么我在以下代码中遇到类型错误(简化):。错误在`{iconMap[名称]}中:。“元素隐式具有”any“类型,因为”string“类型的表达式不能用于索引类型”{ Cate
什么意思: Separator.Iterator.Element == Self.Iterator.Element.Iterator.Element 在this (Swift 标准库)swift 实例
是否可以在 img 元素上使用前后伪选择器?认为它是但没有任何运气,将 css 切换到 div 并且它工作正常。 .page-overhang 类是 img 元素。 // page overhang
我在 UI 中的按钮 Click 事件上有以下代码,它返回一个 MS-Excel 文件。它在第一次点击事件中完美运行,但之后返回以下错误。 任何建议,我怎样才能摆脱它? ERROR: Uncaught
如何在 CSS 中编写这个想法: 选择 ElementA 内但不在 ElementB 内且 ElementB 在 ElementA 内的每个元素。 这是一个例子:
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
如果我在 C# 中的 XElement myXML 变量中有以下 XML, myvalue 要获得“myvalue”,我需要执行以下操作: myXML.Element(
我找不到用户名和密码字段。我检查元素,并尝试通过 id、xpath 或 css 选择器查找它,但它给出错误 NoSuchElementException: Message: no such eleme
我的任务是在用户点击它时从输入框中删除占位符并使标签可见。如果用户未在其中再次填写任何内容,请放回占位符并使标签不可见。 我可以隐藏它但不能重新分配它。我试过 element.setAttribute
我正在编写一个 c# 类来编写一个 XML 文件,该文件需要与我们使用的现有 XML 的结构完全匹配,这样一些遗留系统就不会混淆。 当一个元素的InnerText值为null时,我需要xml元素的元素
自定义元素的一个常见做法,至少在 Polymer(最流行的 Web 组件框架)中,是定义一个新的自定义元素。恕我直言,这对 来说不是一个好习惯呈现 元素,因为该元素无法逐步呈现,必须等到它被加载(注册
我正在尝试跟踪元素的可见性及其显示的控制台错误:“元素“a[data-vars-ei]”必须是 AMP 元素”。 但是在点击跟踪的情况下,类似的事情工作正常。 我无法理解为什么会发生这种情况以及我应该
我是一名优秀的程序员,十分优秀!