If you look at the wml ObjectFactory, you'll see:
Using java Syntax Highlighting
/**
* Create an instance of {@link JAXBElement }{@code <}{@link Text }{@code >}}
*
*/
@XmlElementDecl
(namespace
= "http://schemas.openxmlformats.org/wordprocessingml/2006/main", name
= "instrText", scope
= R.
class)
public JAXBElement
<Text
> createRInstrText
(Text value
) {
return new JAXBElement
<Text
>(_RInstrText_QNAME, Text.
class, R.
class, value
);
}
Parsed in 0.015 seconds, using
GeSHi 1.0.8.4
In other words, w:instrText is represented by JAXBElement<Text>, and that object "knows" it is instrText, via QName("http://schemas.openxmlformats.org/wordprocessingml/2006/main", "instrText");
It is only when you "unwrap" (XmlUtils.unwrap) the JAXBElement that you are left with a bare Text element. The traversal code does this
Using java Syntax Highlighting
/**
* If an object is wrapped in a JAXBElement, return the object.
* Warning: be careful with this. If you are copying objects
* into your document (rather than just reading them), you'll
* probably want the object to remain wrapped (JAXB usually wraps them
* for a reason; without the wrapper, you'll (probably?) need an
* @XmlRootElement annotation in order to be able to marshall ie save your
* document).
*
* @param o
* @return
*/
public static Object unwrap
(Object o
) {
if (o
==null) return null;
if (o
instanceof javax.
xml.
bind.
JAXBElement) {
log.
debug("Unwrapped " + ((JAXBElement
)o
).
getDeclaredType().
getName() );
log.
debug("name: " + ((JAXBElement
)o
).
getName() );
return ((JAXBElement
)o
).
getValue();
} else {
return o
;
}
}
Parsed in 0.014 seconds, using
GeSHi 1.0.8.4
This (JAXBElement) is the pattern which is followed wherever the underlying XML schemas use a complex type for several elements. In this case:
Using xml Syntax Highlighting
<xsd:complexType name="CT_Text">
<xsd:annotation>
<xsd:appinfo>
<jaxb:class name="Text"/>
</xsd:appinfo>
</xsd:annotation>
<xsd:simpleContent>
<xsd:extension base="ST_String">
<xsd:attribute ref="xml:space" use="optional">
<xsd:annotation>
<xsd:documentation>Content Contains Significant
Whitespace
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:simpleContent>
</xsd:complexType>
<xsd:element name="instrText" type="CT_Text">
<xsd:annotation>
<xsd:documentation>Field Code
</xsd:documentation>
</xsd:annotation>
</xsd:element>
Parsed in 0.002 seconds, using
GeSHi 1.0.8.4