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:31:25 +0100

To get

<?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>
    </Document>
</kml>

that's about what you ought to do:

        ObjectFactory of = new ObjectFactory();
        DocumentType doc = of.createDocumentType();
        doc.setName( "testSNPN" );

        JAXBElement<DocumentType> jbedoc = of.createDocument( doc );
        KmlType kml = of.createKmlType();
        kml.setAbstractFeatureGroup( jbedoc );

        JAXBElement<KmlType> jbe = of.createKml( kml );

        JAXBContext ctx = JAXBContext.newInstance( KmlType.class );
        Marshaller m = ctx.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal( jbe, System.out );

-W

On Fri, Mar 6, 2009 at 1:44 PM, Florian Bachmann <f.bachmann_at_micromata.de>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, ...)
>
> 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
>
>
>
>
>
>
>
>
>