Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Placemark.description cannot hold CDATA or unescaped HTML #7

Closed
GoogleCodeExporter opened this issue Jun 29, 2015 · 8 comments
Closed

Comments

@GoogleCodeExporter
Copy link

The description element of placemark is used by GE for content inside the 
balloon. The body content of <description> can be either plain text or 
HTML. If HTML is written into <description>, JAXB escapes the left bracket 
and right bracket into XML entities.

While it still works, in a KML with 250+ placemarks and <description> in 
each placemark, this behavior has taken the file size to 281 KB from 170 
KB when outputting with DOM.

Although its now deprecated, I did find a solution for this: 
https://jaxb.dev.java.net/faq/JaxbCDATASample.java. 

My suggested solutions:
1. Add methods for elements like description to output as CDATA, ie 
placemark.withDescriptionAsCdata("foo")

or

2. Add a method to Kml to allow the developer to use something like a 
serializer: 

public boolean marshall(ContentHandler handler) {
    try {
        m = this.createMarshaller();
        JAXBElement<Kml> jaxbRootElement = new JAXBElement<Kml>(new QName
("http://www.opengis.net/kml/2.2", "kml"), Kml.class, this);
        m.marshal(jaxbRootElement, handler);
        return true;
    } catch (JAXBException _x) {
        _x.printStackTrace();
        return false;
    }
}

By the way, keep up the great work! I was looking into using JAXB directly 
to refactor a servlet generating KML with DOM, but this saved tons of time.

Original issue reported on code.google.com by john.le...@turkeyhill.com on 26 Aug 2009 at 3:43

@GoogleCodeExporter
Copy link
Author

There wasn't a place to select the type. I would consider this as an 
enhancement, 
except maybe that Kml doesn't allow a ContentHandler for marshalling even 
though 
JAXB does.

Original comment by john.le...@turkeyhill.com on 26 Aug 2009 at 3:45

@GoogleCodeExporter
Copy link
Author

Original comment by bachmann...@gmail.com on 26 Aug 2009 at 8:06

  • Changed state: Accepted

@GoogleCodeExporter
Copy link
Author

I added the public boolean marshal(ContentHandler) {...} method. (in r30.
http://code.google.com/p/javaapiforkml/source/detail?r=30)

Please let me know, if it is enough and you're now able to serialize your CDATA 
code
correctly.

Original comment by bachmann...@gmail.com on 27 Aug 2009 at 2:26

@GoogleCodeExporter
Copy link
Author

just give me a moment more, until I release r31...

Original comment by bachmann...@gmail.com on 27 Aug 2009 at 2:51

@GoogleCodeExporter
Copy link
Author

Original comment by bachmann...@gmail.com on 28 Aug 2009 at 8:12

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

I set up my code like the JAXB FAQ suggested, but for whatever reason the 
serializer 
just won't pick up on the description element. I 
tried "^description", "description", ":description"... no dice.

Oh well... thanks for the enhancement. The marshaller does use the 
ContentHandler. 
Hopefully the JAXB team will change the FAQ to a way that isn't deprecated.

Original comment by john.le...@turkeyhill.com on 28 Aug 2009 at 4:32

@GoogleCodeExporter
Copy link
Author

Is this really fixed?  I am struggling to get this to work.  I have tried used 
the  https://jaxb.dev.java.net/faq/JaxbCDATASample.java solution but it does 
not affect the 'description' element in any way.  Anyone have any success?


Original comment by nkhosra...@gmail.com on 27 Jul 2011 at 4:33

@GoogleCodeExporter
Copy link
Author

Anyone fixed the problem?
It still does not work.

This is my code:
outputFormat.setCDataElements( new String[] { "description"}); 

             outputFormat.setPreserveSpace(true);
             outputFormat.setIndenting(true);
             org.apache.xml.serialize.XMLSerializer  xmlSerializer=new org.apache.xml.serialize.XMLSerializer  (fileWriter,outputFormat);           
             kml.marshal(xmlSerializer.asContentHandler());

Original comment by ahwangyu...@gmail.com on 28 Mar 2013 at 2:17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant