更新
根据您的评论:
Hi.. Thanks for your reply.. @Blaise
Doughan & @CoolBeans in the above
example you provide you have mentioned
String Value but in my
xml, instead of “String Value” there
will be another XML inside it. like
Richard
and I need the
“Richard” as
string in the output. Please let me
know still you want more information.
Thanks.. Cheers, Sakthi. S
您可以结合使用@XmlAnyElement和DomHandler实现来处理此用例.有关详细示例,请参见:
更新#2
根据您的评论
Can you please tell me what is change
need to be done in the schema to make
that filed “@XmlAnyElement”, since I
am generating the java classes on the
build time.
您可以使用JAXB dom模式注释来导致在属性上生成XmlAnyElement:
XJC电话
xjc -d out -b bindings.xml dom.xsd
dom.xsd
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.com/default"
targetNamespace="http://www.example.com/default">
bindings.xml
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
version="2.1">
顾客
客户的地址属性将使用@XmlAnyElement进行注释:
package com.example._default;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAnyElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;
import org.w3c.dom.Element;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"address"
})
@XmlRootElement(name = "customer")
public class Customer {
@XmlAnyElement
protected Element address;
public Element getAddress() {
return address;
}
public void setAddress(Element value) {
this.address = value;
}
}
原始答案
您可能正在寻找@XmlValue批注.例如,如果您有以下课程:
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD
public class Child {
@XmlValue
private String value;
}
上等人将编组为:
String Value
在相应的XML模式中,子元素的类型为xs:string.