一段时间以来,我无法将名称空间添加到属性。我的要求是创建 xml,它将在子元素而不是根元素上具有命名空间 uri。我将 jaxb 与 eclipselink moxy、jdk7 一起使用。
<document>
<Date> date </Date>
</Type>type </Type>
<customFields xmlns:pns="http://abc.com/test.xsd">
<id>..</id>
<contact>..</contact>
</customFields>
</document>
Classes are:
@XmlRootElement(name = "document")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(propOrder = {"type","date", "customFields"})
public class AssetBean {
@XmlElement(name="Type")
private String type;
@XmlElement(name="Date")
@XmlElement(name = "CustomFields",namespace = "http://api.source.com/xsds/path/to/partner.xsd")
private CustomBean customFields = new CustomBean();
//getters/setters here
}
public class CustomBean {
private String id;
private String contact;
//getter/setter
}
package-info.java
@javax.xml.bind.annotation.XmlSchema (
xmlns = {
@javax.xml.bind.annotation.XmlNs(prefix="pns",
namespaceURI="http://api.source.com/xsds/path/to/partner.xsd")
},
elementFormDefault = javax.xml.bind.annotation.XmlNsForm.UNQUALIFIED
)
package com.abc.xyz
我按照这篇文章寻求帮助,但无法得到我正在尝试的东西 http://blog.bdoughan.com/2010/08/jaxb-namespaces.html
谢谢