JAXB and multiple namespaces

View: New views
2 Messages — Rating Filter:   Alert me  

JAXB and multiple namespaces

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I am trying to parse an XML document that consists of multiple
namespaces, as in:
<pre>
<eec:attr>
   <eec:title>Summary List of samples</eec:title>
   <eec:name>samples_list</eec:name>
   <eec:type>textarea</eec:type>
   <eec:value><p>Nd<sub>2</sub>F<sub>14</sub>B</p></eec:value>
 </eec:attr>
</pre>
I want to map the "eec:" namespace into a java object, but I want JAXB
to leave the empty namespace (xhtml) as a single string.  ie. the
entire piece of xhtml in the "eec:value" element should be the value
of a single JAXB object property.

It seems like I'm supposed to create my own JAXB XmlAdapter, but I'm
completely unfamiliar with the JAXB API.  Can anyone point me to the
right place to start?

Message was edited by: bleathem
[Message sent by forum member 'bleathem' (bleathem@...)]

http://forums.java.net/jive/thread.jspa?messageID=370573

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


Re: JAXB and multiple namespaces

by metro-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ok, problem solved.  The embedded arbitrary xhtml is represented using the "<xs:any" tag.  JAXB unmarhsalled the xhtml into DOM Element interfaces [1].  It was then fairly trivial to take this Element instance, and transform it back to XML.  I used this method [2]:

[code]
private String nodeToString(Node node) {
StringWriter sw = new StringWriter();
try {
Transformer t = TransformerFactory.newInstance().newTransformer();
t.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
t.transform(new DOMSource(node), new StreamResult(sw));
} catch (TransformerException te) {
System.out.println("nodeToString Transformer Exception");
}
return sw.toString();
}
[/code]


[1] [code]http://fisheye5.cenqua.com/browse/~raw,r=1.1.1.10/jaxb/www/guide/Mapping_of__xs_any___.html[/code]
[2] [code]http://projectwownow.blogspot.com/2008/08/java-node-to-string-conversion.html[/code]
[Message sent by forum member 'bleathem' (bleathem@...)]

http://forums.java.net/jive/thread.jspa?messageID=370729

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...