users@jaxb.java.net

Re: XmlRootElement to influence tag-name? Or how to get rid of <AbstractClasss xmlns:xsi="..." xsi:type="DocumentType">

From: Wolfgang Laun <wolfgang.laun_at_gmail.com>
Date: Fri, 6 Mar 2009 14:34:55 +0100

I don't think you have to add these @XmlRootElement annotations, just watch
out for the way the plain *Type classes are to be interleaved with JAXB's
wrapper elements JAXBElement<*Type>.
-W

On Fri, Mar 6, 2009 at 2:32 PM, Florian Bachmann <f.bachmann_at_micromata.de>wrote:

> sorry, I had an typo in my original mail,I'm already
> using @XmlRootElement(name="foo")
> to annotate my classes.
>
>
> I add the @XmlRootElement()-annotation via a plugin.
> @Override
> public boolean run(Outline outline, Options opts, ErrorHandler
> errorHandler) {
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement = newHashMap<String, String>();
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("camera",
> "Camera");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("document",
> "Document");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("folder",
> "Folder");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("groundoverlay",
> "GroundOverlay");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("kml", "kml");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("linearring",
> "LienarRing");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("linestring",
> "LineString");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("lookat",
> "LookAt");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("model", "Model"
> );
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("multigeometry",
> "MultiGeometry");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("networklink",
> "NetworkLink");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("photooverlay",
> "PhotoOverlay");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("placemark",
> "Placemark");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("point", "Point"
> );
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("polygon",
> "Polygon");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("screenoverlay",
> "ScreenOverlay");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("stylemap",
> "StyleMap");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("style", "Style"
> );
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("timespan",
> "TimeSpan");
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement.put("timestamp",
> "TimeStamp");
>
> for (final ClassOutline classOutline : outline.getClasses()) {
> annotateClasses((ClassOutlineImpl) classOutline);
> }
>
> return true;
> }
>
>
> private void annotateClasses(final ClassOutlineImpl cc) {
> String currentClassName = cc.implRef.name().toLowerCase();
> if (quickAndSimpleAnnotateTheseElementsWithXmlRootElement.containsKey(currentClassName))
> {
> ...
> String mostUsedNamespaceURI = cc._package().getMostUsedNamespaceURI();
> String xmlRootElementName =
> quickAndSimpleAnnotateTheseElementsWithXmlRootElement
> .get(currentClassName);
> // [RESULT]
> // @XmlRootElement(name = "foo", namespace = "bar://baz")
> XmlRootElementWriter xrew = cc.implClass.annotate2(XmlRootElementWriter.
> class);
> xrew.name(xmlRootElementName);
> xrew.namespace(mostUsedNamespaceURI);
> LOG.info("> added @XmlRootElement(name = '" + xmlRootElementName + "',
> namespace = '" + mostUsedNamespaceURI + "')");
> // LOG.info("> added @XmlRootElement(name = '" + xmlRootElementName +
> "')");
> }
> }
>
>
> bye
> Flori
>
>
> Am 06.03.2009 um 14:02 schrieb Pavel Bucek:
>
> Hello,
>
> see
> http://java.sun.com/javase/6/docs/api/javax/xml/bind/annotation/XmlRootElement.html
>
> Correct way to change name of generated element is
> @XmlRootElement(name="foo")
>
> Regards,
>
> Pavel
>
>
> Florian Bachmann wrote:
>
> Dear JAXB team,
>
> I created a bunch of classes from the ogc kml-schema
>
> (used by Google Earth and Google Maps and found here:
>
> http://www.opengeospatial.org/standards/kml/ ).
>
>
> So far so good, but as soon I want to marshal some objects into
>
> an xml/kml-file I get this output:
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>
> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="
> http://www.w3.org/2005/Atom" xmlns:ns3="
> urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
>
> <AbstractFeatureGroup xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:type="DocumentType">
>
> <name>testSNPN</name>
>
> <abstractFeatureGroup xsi:type="PlacemarkType">
>
> <name>P1</name>
>
> <AbstractGeometryGroup xsi:type="LineStringType">
>
> <tessellate>true</tessellate>
>
> <coordinates>-122.370533,37.823842,0</coordinates>
>
> </AbstractGeometryGroup>
>
> </abstractFeatureGroup>
>
> </AbstractFeatureGroup>
>
> </kml>
>
>
> but the produced output isn't readable by Google Earth.
>
> Especially the <AbstractFeatureGroup xmlns:xsi="
> http://www.w3.org/2001/XMLSchema-instance" xsi:type="DocumentType"> part,
> should be only <Document>
>
> and the whole should be:
>
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
>
> <kml xmlns="http://www.opengis.net/kml/2.2" xmlns:ns2="
> http://www.w3.org/2005/Atom" xmlns:ns3="
> urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
>
> <Document>
>
> <name>testSNPN</name>
>
> <Placemark>
>
> <name>P1</name>
>
> <LineString>
>
> <tessellate>true</tessellate>
>
> <coordinates>-122.370533,37.823842,0</coordinates>
>
> </LineString >
>
> </Placemark>
>
> </Document >
>
> </kml>
>
>
>
> So my question is it possible to affect the tag-name?
>
> (From "DocumentType" to "Document" and the whole from
> <AbstractFeatureGroup ... xsi:type="DocumentType"> direct into the type?
>
>
> I tried to add @XmlRootElement() to each class
>
> (@XmlRootElement("Document") to the DocumentType-class,
> @XmlRootElement("Placemark") to the Placemarktype-class, ...)
>
>
> TYPO:
> i meant:
>
> @XmlRootElement(name= "Document") to the DocumentType-class,
> @XmlRootElement(name="Placemark") to the Placemarktype-class, ...)
>
>
>
> but it doesn't seem to have any influence to the marshalled output.
>
>
> Could anybody give me a hint, to get the desired output?
>
>
> regards Flori
>
>
>
>
>
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jaxb.dev.java.net
> For additional commands, e-mail: users-help_at_jaxb.dev.java.net
>
>
>