From 28d3599ef601b5ad3fff3b630cbd2b87f4c65dbd Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Wed, 21 Oct 2009 01:41:50 -0400 Subject: [PATCH] Added XML escaping to the KML classes. --- src/KML.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/KML.py b/src/KML.py index 4b6d12f..f96adb2 100644 --- a/src/KML.py +++ b/src/KML.py @@ -3,6 +3,7 @@ Utility classes for working with the Keyhole Markup Language (KML). """ import sys +from xml.sax.saxutils import escape class KmlObject(object): @@ -36,7 +37,7 @@ class KmlObject(object): def render(self): kml = self.OPEN_TAG - kml += self.text + kml += escape(self.text) for c in self.children: kml += c.to_kml() @@ -53,8 +54,8 @@ class KmlObject(object): def render_to_stdout(self): - if not (len(self.text) == 0): - print self.text + if (len(self.text) > 0): + print escape(self.text) for c in self.children: c.print_kml() @@ -164,4 +165,10 @@ class StyleUrl(KmlObject): class RawText(KmlObject): - pass + + def to_kml(self): + return self.text + + def print_kml(self): + if (len(self.text) > 0): + print self.text -- 2.44.2