[OpenLayers-Commits] r12108 - in trunk/openlayers:
lib/OpenLayers/Format tests/Format
commits-20090109 at openlayers.org
commits-20090109 at openlayers.org
Sat Jun 18 15:33:30 EDT 2011
Author: ahocevar
Date: 2011-06-18 12:33:29 -0700 (Sat, 18 Jun 2011)
New Revision: 12108
Modified:
trunk/openlayers/lib/OpenLayers/Format/XML.js
trunk/openlayers/tests/Format/XML.html
Log:
adding getXMLDoc method that allows creating XML documents with non-HTML compliant nodes (e.g. createCDATASection). r=bartvde (closes #3366)
Modified: trunk/openlayers/lib/OpenLayers/Format/XML.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/Format/XML.js 2011-06-18 19:27:27 UTC (rev 12107)
+++ trunk/openlayers/lib/OpenLayers/Format/XML.js 2011-06-18 19:33:29 UTC (rev 12108)
@@ -848,6 +848,29 @@
return uri;
},
+ /**
+ * Method: getXMLDoc
+ * Get an XML document for nodes that are not supported in HTML (e.g.
+ * createCDATASection). On IE, this will either return an existing or
+ * create a new <xmldom> on the instance. On other browsers, this will
+ * either return an existing or create a new shared document (see
+ * <OpenLayers.Format.XML.document>).
+ *
+ * Returns:
+ * {XMLDocument}
+ */
+ getXMLDoc: function() {
+ if (!OpenLayers.Format.XML.document && !this.xmldom) {
+ if (document.implementation && document.implementation.createDocument) {
+ OpenLayers.Format.XML.document =
+ document.implementation.createDocument("", "", null);
+ } else if (!this.xmldom && window.ActiveXObject) {
+ this.xmldom = new ActiveXObject("Microsoft.XMLDOM");
+ }
+ }
+ return OpenLayers.Format.XML.document || this.xmldom;
+ },
+
CLASS_NAME: "OpenLayers.Format.XML"
});
@@ -879,3 +902,10 @@
OpenLayers.Format.XML.prototype.lookupNamespaceURI,
OpenLayers.Format.XML.prototype
);
+
+/**
+ * Property: OpenLayers.Format.XML.document
+ * {XMLDocument} XML document to reuse for creating non-HTML compliant nodes,
+ * like document.createCDATASection.
+ */
+OpenLayers.Format.XML.document = null;
Modified: trunk/openlayers/tests/Format/XML.html
===================================================================
--- trunk/openlayers/tests/Format/XML.html 2011-06-18 19:27:27 UTC (rev 12107)
+++ trunk/openlayers/tests/Format/XML.html 2011-06-18 19:33:29 UTC (rev 12108)
@@ -849,6 +849,19 @@
}
+ function test_getXMLDoc(t) {
+ t.plan(2);
+ var format = new OpenLayers.Format.XML();
+ var doc = format.getXMLDoc();
+ t.ok(doc !== document, "document returned from getXMLDoc is not the page's html doc");
+ var root = format.createElementNS("http://test", "root");
+ // appending CDATA created from a different document
+ var cdata = doc.createCDATASection("<foo></foo>");
+ root.appendChild(cdata);
+ var result = format.write(root);
+ var expect = '<root xmlns="http://test"><![CDATA[<foo></foo>]]></root>';
+ t.eq(result, expect, "document with CDATA section serialized correctly");
+ }
</script>
More information about the Commits
mailing list