JAXB Unable To Handle Attribute with Colon (:) in name?
Posted
by Intellectual Tortoise
on Stack Overflow
See other posts from Stack Overflow
or by Intellectual Tortoise
Published on 2010-06-09T13:45:17Z
Indexed on
2010/06/11
13:33 UTC
Read the original article
Hit count: 162
I am attempting to use JAXB to unmarshall an XML files whose schema is defined by a DTD (ugh!).
The external provider of the DTD has specified one of the element attributes as xml:lang
:
<!ATTLIST langSet
id ID #IMPLIED
xml:lang CDATA #REQUIRED
>
This comes into the xjc-generated class (standard generation; no *.xjb magic) as:
@XmlAttribute(name = "xml:lang", required = true)
@XmlJavaTypeAdapter(NormalizedStringAdapter.class)
protected String xmlLang;
However, when unmarshalling valid XML files with JAXB, the xmlLang
attribute is always null
.
When I edited the XML file, replacing xml:lang
with lang
and changed the @XmlAttribute
to match, unmarshalling was successful (i.e. attributes were non-null
).
I did find this http://old.nabble.com/unmarshalling-ignores-element-attribute-%27xml%27-td22558466.html. But, the resolution there was to convert to XML Schema, etc. My strong preference is to go straight from an un-altered DTD (since it is externally provided and defined by an ISO standard).
Is this a JAXB bug? Am I missing something about "namespaces" in attribute names?
FWIW, java -version
= "build 1.6.0_20-b02" and xjc -version
= "xjc version "JAXB 2.1.10 in JDK 6""
© Stack Overflow or respective owner