From ba2d39e683909e9b341f8e630cc7df11cf77d59b Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Fri, 24 Oct 2014 15:34:50 +0200 Subject: [PATCH 1/4] Export useful xml functions --- src/ol/xml.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ol/xml.js b/src/ol/xml.js index 6c8e0d4da5..97ede601e7 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -80,6 +80,7 @@ ol.xml.createElementNS = * @param {Node} node Node. * @param {boolean} normalizeWhitespace Normalize whitespace. * @return {string} All text content. + * @api */ ol.xml.getAllTextContent = function(node, normalizeWhitespace) { return ol.xml.getAllTextContent_(node, normalizeWhitespace, []).join(''); @@ -334,6 +335,7 @@ ol.xml.setAttributeNS = /** * @param {string} xml XML. * @return {Document} Document. + * @api */ ol.xml.load = function(xml) { return new DOMParser().parseFromString(xml, 'application/xml'); From 757b6a214c595ac610568be296d3063aad5df9ef Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Mon, 27 Oct 2014 10:55:21 +0100 Subject: [PATCH 2/4] Rename ol.xml.parse to ol.xml.parseNode --- src/ol/format/gml/gml3.js | 4 ++-- src/ol/format/gml/gmlbase.js | 6 +++--- src/ol/format/gpxformat.js | 4 ++-- src/ol/format/kmlformat.js | 4 ++-- src/ol/format/wfsformat.js | 2 +- src/ol/xml.js | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/ol/format/gml/gml3.js b/src/ol/format/gml/gml3.js index ca4a77488e..fc53a3bdde 100644 --- a/src/ol/format/gml/gml3.js +++ b/src/ol/format/gml/gml3.js @@ -142,7 +142,7 @@ ol.format.GML3.prototype.curveMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'curveMember' || node.localName == 'curveMembers'); - ol.xml.parse(this.CURVEMEMBER_PARSERS_, node, objectStack, this); + ol.xml.parseNode(this.CURVEMEMBER_PARSERS_, node, objectStack, this); }; @@ -155,7 +155,7 @@ ol.format.GML3.prototype.surfaceMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'surfaceMember' || node.localName == 'surfaceMembers'); - ol.xml.parse(this.SURFACEMEMBER_PARSERS_, + ol.xml.parseNode(this.SURFACEMEMBER_PARSERS_, node, objectStack, this); }; diff --git a/src/ol/format/gml/gmlbase.js b/src/ol/format/gml/gmlbase.js index 83b33f63ed..b957ed2385 100644 --- a/src/ol/format/gml/gmlbase.js +++ b/src/ol/format/gml/gmlbase.js @@ -274,7 +274,7 @@ ol.format.GMLBase.prototype.pointMemberParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'pointMember' || node.localName == 'pointMembers'); - ol.xml.parse(this.POINTMEMBER_PARSERS_, + ol.xml.parseNode(this.POINTMEMBER_PARSERS_, node, objectStack, this); }; @@ -289,7 +289,7 @@ ol.format.GMLBase.prototype.lineStringMemberParser_ = goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'lineStringMember' || node.localName == 'lineStringMembers'); - ol.xml.parse(this.LINESTRINGMEMBER_PARSERS_, + ol.xml.parseNode(this.LINESTRINGMEMBER_PARSERS_, node, objectStack, this); }; @@ -304,7 +304,7 @@ ol.format.GMLBase.prototype.polygonMemberParser_ = goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'polygonMember' || node.localName == 'polygonMembers'); - ol.xml.parse(this.POLYGONMEMBER_PARSERS_, node, + ol.xml.parseNode(this.POLYGONMEMBER_PARSERS_, node, objectStack, this); }; diff --git a/src/ol/format/gpxformat.js b/src/ol/format/gpxformat.js index 23492bbccd..ad40a92393 100644 --- a/src/ol/format/gpxformat.js +++ b/src/ol/format/gpxformat.js @@ -100,7 +100,7 @@ ol.format.GPX.parseLink_ = function(node, objectStack) { if (!goog.isNull(href)) { goog.object.set(values, 'link', href); } - ol.xml.parse(ol.format.GPX.LINK_PARSERS_, node, objectStack); + ol.xml.parseNode(ol.format.GPX.LINK_PARSERS_, node, objectStack); }; @@ -164,7 +164,7 @@ ol.format.GPX.parseTrkSeg_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'trkseg'); var values = /** @type {Object} */ (objectStack[objectStack.length - 1]); - ol.xml.parse(ol.format.GPX.TRKSEG_PARSERS_, node, objectStack); + ol.xml.parseNode(ol.format.GPX.TRKSEG_PARSERS_, node, objectStack); var flatCoordinates = /** @type {Array.} */ (goog.object.get(values, 'flatCoordinates')); var ends = /** @type {Array.} */ (goog.object.get(values, 'ends')); diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 42f088ae7a..85d28a228e 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -1000,7 +1000,7 @@ ol.format.KML.DataParser_ = function(node, objectStack) { ol.format.KML.ExtendedDataParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'ExtendedData'); - ol.xml.parse(ol.format.KML.EXTENDED_DATA_PARSERS_, node, objectStack); + ol.xml.parseNode(ol.format.KML.EXTENDED_DATA_PARSERS_, node, objectStack); }; @@ -1066,7 +1066,7 @@ ol.format.KML.PlacemarkStyleMapParser_ = function(node, objectStack) { ol.format.KML.SchemaDataParser_ = function(node, objectStack) { goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT); goog.asserts.assert(node.localName == 'SchemaData'); - ol.xml.parse(ol.format.KML.SCHEMA_DATA_PARSERS_, node, objectStack); + ol.xml.parseNode(ol.format.KML.SCHEMA_DATA_PARSERS_, node, objectStack); }; diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 51e2ae9905..055efdf447 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -278,7 +278,7 @@ ol.format.WFS.OGC_FID_PARSERS_ = { * @private */ ol.format.WFS.fidParser_ = function(node, objectStack) { - ol.xml.parse(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack); + ol.xml.parseNode(ol.format.WFS.OGC_FID_PARSERS_, node, objectStack); }; diff --git a/src/ol/xml.js b/src/ol/xml.js index 97ede601e7..d4844472ae 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -643,7 +643,7 @@ ol.xml.makeStructureNS = function(namespaceURIs, structure, opt_structureNS) { * @param {Array.<*>} objectStack Object stack. * @param {*=} opt_this The object to use as `this`. */ -ol.xml.parse = function(parsersNS, node, objectStack, opt_this) { +ol.xml.parseNode = function(parsersNS, node, objectStack, opt_this) { var n; for (n = node.firstElementChild; !goog.isNull(n); n = n.nextElementSibling) { var parsers = parsersNS[n.namespaceURI]; @@ -670,7 +670,7 @@ ol.xml.parse = function(parsersNS, node, objectStack, opt_this) { ol.xml.pushParseAndPop = function( object, parsersNS, node, objectStack, opt_this) { objectStack.push(object); - ol.xml.parse(parsersNS, node, objectStack, opt_this); + ol.xml.parseNode(parsersNS, node, objectStack, opt_this); return objectStack.pop(); }; From 88d1258e83c2ae1cd77613b5b1c0796710fcfc48 Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Mon, 27 Oct 2014 11:00:09 +0100 Subject: [PATCH 3/4] Rename ol.xml.load to ol.xml.parse --- src/ol/format/kmlformat.js | 2 +- src/ol/format/wfsformat.js | 4 +- src/ol/format/xmlfeatureformat.js | 8 ++-- src/ol/format/xmlformat.js | 2 +- src/ol/source/formatvectorsource.js | 2 +- src/ol/xml.js | 3 +- test/spec/ol/format/gmlformat.test.js | 40 ++++++++--------- test/spec/ol/format/gpxformat.test.js | 28 ++++++------ test/spec/ol/format/kmlformat.test.js | 62 +++++++++++++-------------- test/spec/ol/format/owsformat.test.js | 6 +-- test/spec/ol/format/wfsformat.test.js | 18 ++++---- 11 files changed, 88 insertions(+), 87 deletions(-) diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js index 85d28a228e..dc6d457d89 100644 --- a/src/ol/format/kmlformat.js +++ b/src/ol/format/kmlformat.js @@ -1655,7 +1655,7 @@ ol.format.KML.prototype.readName = function(source) { } else if (ol.xml.isNode(source)) { return this.readNameFromNode(/** @type {Node} */ (source)); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readNameFromDocument(doc); } else { goog.asserts.fail(); diff --git a/src/ol/format/wfsformat.js b/src/ol/format/wfsformat.js index 055efdf447..ea9ab4a6b5 100644 --- a/src/ol/format/wfsformat.js +++ b/src/ol/format/wfsformat.js @@ -149,7 +149,7 @@ ol.format.WFS.prototype.readTransactionResponse = function(source) { } else if (ol.xml.isNode(source)) { return this.readTransactionResponseFromNode(/** @type {Node} */ (source)); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readTransactionResponseFromDocument(doc); } else { goog.asserts.fail(); @@ -172,7 +172,7 @@ ol.format.WFS.prototype.readFeatureCollectionMetadata = function(source) { return this.readFeatureCollectionMetadataFromNode( /** @type {Node} */ (source)); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readFeatureCollectionMetadataFromDocument(doc); } else { goog.asserts.fail(); diff --git a/src/ol/format/xmlfeatureformat.js b/src/ol/format/xmlfeatureformat.js index 3c61ee6574..7dea0579b5 100644 --- a/src/ol/format/xmlfeatureformat.js +++ b/src/ol/format/xmlfeatureformat.js @@ -43,7 +43,7 @@ ol.format.XMLFeature.prototype.readFeature = function(source, opt_options) { } else if (ol.xml.isNode(source)) { return this.readFeatureFromNode(/** @type {Node} */ (source), opt_options); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readFeatureFromDocument(doc, opt_options); } else { goog.asserts.fail(); @@ -86,7 +86,7 @@ ol.format.XMLFeature.prototype.readFeatures = function(source, opt_options) { } else if (ol.xml.isNode(source)) { return this.readFeaturesFromNode(/** @type {Node} */ (source), opt_options); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readFeaturesFromDocument(doc, opt_options); } else { goog.asserts.fail(); @@ -134,7 +134,7 @@ ol.format.XMLFeature.prototype.readGeometry = function(source, opt_options) { } else if (ol.xml.isNode(source)) { return this.readGeometryFromNode(/** @type {Node} */ (source), opt_options); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readGeometryFromDocument(doc, opt_options); } else { goog.asserts.fail(); @@ -170,7 +170,7 @@ ol.format.XMLFeature.prototype.readProjection = function(source) { } else if (ol.xml.isNode(source)) { return this.readProjectionFromNode(/** @type {Node} */ (source)); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readProjectionFromDocument(doc); } else { goog.asserts.fail(); diff --git a/src/ol/format/xmlformat.js b/src/ol/format/xmlformat.js index 111bf5f511..11d46fbe6a 100644 --- a/src/ol/format/xmlformat.js +++ b/src/ol/format/xmlformat.js @@ -25,7 +25,7 @@ ol.format.XML.prototype.read = function(source) { } else if (ol.xml.isNode(source)) { return this.readFromNode(/** @type {Node} */ (source)); } else if (goog.isString(source)) { - var doc = ol.xml.load(source); + var doc = ol.xml.parse(source); return this.readFromDocument(doc); } else { goog.asserts.fail(); diff --git a/src/ol/source/formatvectorsource.js b/src/ol/source/formatvectorsource.js index 81b0dd7e9b..1ceba4d297 100644 --- a/src/ol/source/formatvectorsource.js +++ b/src/ol/source/formatvectorsource.js @@ -91,7 +91,7 @@ ol.source.FormatVector.prototype.loadFeaturesFromURL = source = xhrIo.getResponseXml(); } if (!goog.isDefAndNotNull(source)) { - source = ol.xml.load(xhrIo.getResponseText()); + source = ol.xml.parse(xhrIo.getResponseText()); } } else { goog.asserts.fail(); diff --git a/src/ol/xml.js b/src/ol/xml.js index d4844472ae..249713fca2 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -333,11 +333,12 @@ ol.xml.setAttributeNS = /** + * Parse an XML string to a XML Document * @param {string} xml XML. * @return {Document} Document. * @api */ -ol.xml.load = function(xml) { +ol.xml.parse = function(xml) { return new DOMParser().parseFromString(xml, 'application/xml'); }; diff --git a/test/spec/ol/format/gmlformat.test.js b/test/spec/ol/format/gmlformat.test.js index 668f1aa9ea..3aeece75f5 100644 --- a/test/spec/ol/format/gmlformat.test.js +++ b/test/spec/ol/format/gmlformat.test.js @@ -1,7 +1,7 @@ goog.provide('ol.test.format.GML'); var readGeometry = function(format, text, opt_options) { - var doc = ol.xml.load(text); + var doc = ol.xml.parse(text); // we need an intermediate node for testing purposes var node = goog.dom.createElement(goog.dom.TagName.PRE); node.appendChild(doc.documentElement); @@ -131,7 +131,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.Point); expect(g.getCoordinates()).to.eql([1, 2, 0]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read a point geometry with scientific notation', function() { @@ -201,7 +201,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.Point); expect(g.getCoordinates()).to.eql([1, 2, 0]); var serialized = formatWGS84.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -218,7 +218,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.LineString); expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read, transform and write a linestring geometry', function() { @@ -257,7 +257,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.LineString); expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); var serialized = formatWGS84.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -275,7 +275,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.LineString); expect(g.getCoordinates()).to.eql([[-180, -90, 0], [180, 90, 0]]); var serialized = formatWGS84.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read and write a point geometry with correct axis order', @@ -289,7 +289,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.Point); expect(g.getCoordinates()).to.eql([-180, -90, 0]); var serialized = formatWGS84.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read and write a surface geometry with right axis order', @@ -320,7 +320,7 @@ describe('ol.format.GML3', function() { srsName: 'urn:x-ogc:def:crs:EPSG:4326', surface: false}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -353,7 +353,7 @@ describe('ol.format.GML3', function() { expect(g.getCoordinates()).to.eql( [[1, 2, 0], [3, 4, 0], [5, 6, 0], [1, 2, 0]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -386,7 +386,7 @@ describe('ol.format.GML3', function() { [1, 2, 0]], [[2, 3, 0], [2, 5, 0], [4, 5, 0], [2, 3, 0]], [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -424,7 +424,7 @@ describe('ol.format.GML3', function() { [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]]); format = new ol.format.GML({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -446,7 +446,7 @@ describe('ol.format.GML3', function() { expect(g.getCoordinates()).to.eql([[1, 2, 0], [3, 4, 0]]); format = new ol.format.GML({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -492,7 +492,7 @@ describe('ol.format.GML3', function() { expect(g).to.be.an(ol.geom.MultiPoint); expect(g.getCoordinates()).to.eql([[1, 2, 0], [2, 3, 0], [3, 4, 0]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read a plural multipoint geometry', function() { @@ -541,7 +541,7 @@ describe('ol.format.GML3', function() { [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); format = new ol.format.GML({srsName: 'CRS:84', multiCurve: false}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read a plural multilinestring geometry', function() { @@ -609,7 +609,7 @@ describe('ol.format.GML3', function() { [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); format = new ol.format.GML({srsName: 'CRS:84', multiSurface: false}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read a plural multipolygon geometry', function() { @@ -677,7 +677,7 @@ describe('ol.format.GML3', function() { expect(g.getCoordinates()).to.eql( [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read and write a singular multicurve-curve geometry', function() { @@ -709,7 +709,7 @@ describe('ol.format.GML3', function() { [[[1, 2, 0], [2, 3, 0]], [[3, 4, 0], [4, 5, 0]]]); format = new ol.format.GML({srsName: 'CRS:84', curve: true}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -757,7 +757,7 @@ describe('ol.format.GML3', function() { [[3, 4, 0], [3, 6, 0], [5, 6, 0], [3, 4, 0]]], [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); it('can read a plural multisurface geometry', function() { @@ -852,7 +852,7 @@ describe('ol.format.GML3', function() { [[[1, 2, 0], [3, 2, 0], [3, 4, 0], [1, 2, 0]]]]); format = new ol.format.GML({srsName: 'CRS:84', surface: true}); var serialized = format.writeGeometry(g); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -979,7 +979,7 @@ describe('ol.format.GML3', function() { it('writes back features as GML', function() { this.timeout(4000); var serialized = gmlFormat.writeFeatures(features); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); diff --git a/test/spec/ol/format/gpxformat.test.js b/test/spec/ol/format/gpxformat.test.js index d26b101553..482a640856 100644 --- a/test/spec/ol/format/gpxformat.test.js +++ b/test/spec/ol/format/gpxformat.test.js @@ -56,7 +56,7 @@ describe('ol.format.GPX', function() { expect(f.get('number')).to.be(1); expect(f.get('type')).to.be('Type'); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a rte with multiple rtepts', function() { @@ -76,7 +76,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([[2, 1, 0, 0], [4, 3, 0, 0]]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can transform, read and write a rte', function() { @@ -104,7 +104,7 @@ describe('ol.format.GPX', function() { var serialized = format.writeFeatures(fs, { featureProjection: 'EPSG:3857' }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -156,7 +156,7 @@ describe('ol.format.GPX', function() { expect(f.get('number')).to.be(1); expect(f.get('type')).to.be('Type'); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a trk with an empty trkseg', function() { @@ -175,7 +175,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([[]]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read/write a trk with a trkseg with multiple trkpts', function() { @@ -205,7 +205,7 @@ describe('ol.format.GPX', function() { ]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can tranform, read and write a trk with a trkseg', function() { @@ -241,7 +241,7 @@ describe('ol.format.GPX', function() { var serialized = format.writeFeatures(fs, { featureProjection: 'EPSG:3857' }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a trk with multiple trksegs', function() { @@ -282,7 +282,7 @@ describe('ol.format.GPX', function() { ]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -303,7 +303,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([2, 1, 0, 0]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can transform, read and write a wpt', function() { @@ -326,7 +326,7 @@ describe('ol.format.GPX', function() { var serialized = format.writeFeatures(fs, { featureProjection: 'EPSG:3857' }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a wpt with ele', function() { @@ -345,7 +345,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([2, 1, 3, 0]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a wpt with time', function() { @@ -364,7 +364,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([2, 1, 0, 1263115752]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write a wpt with ele and time', function() { @@ -384,7 +384,7 @@ describe('ol.format.GPX', function() { expect(g.getCoordinates()).to.eql([2, 1, 3, 1263115752]); expect(g.getLayout()).to.be(ol.geom.GeometryLayout.XYZM); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('can read and write various wpt attributes', function() { @@ -434,7 +434,7 @@ describe('ol.format.GPX', function() { expect(f.get('ageofdgpsdata')).to.be(9); expect(f.get('dgpsid')).to.be(10); var serialized = format.writeFeatures(fs); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); diff --git a/test/spec/ol/format/kmlformat.test.js b/test/spec/ol/format/kmlformat.test.js index 83b32c4a72..8267cfe1ce 100644 --- a/test/spec/ol/format/kmlformat.test.js +++ b/test/spec/ol/format/kmlformat.test.js @@ -47,7 +47,7 @@ describe('ol.format.KML', function() { ' https://developers.google.com/kml/schema/kml22gx.xsd">' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write a Feature\'s id', function() { @@ -63,7 +63,7 @@ describe('ol.format.KML', function() { ' https://developers.google.com/kml/schema/kml22gx.xsd">' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); }); @@ -94,7 +94,7 @@ describe('ol.format.KML', function() { ' https://developers.google.com/kml/schema/kml22gx.xsd">' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read Point geometries', function() { @@ -206,7 +206,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZ Point geometries', function() { @@ -226,7 +226,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can transform and write XYZ Point geometries', function() { @@ -258,7 +258,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); ol.proj.removeTransform( ol.proj.get('EPSG:4326'), ol.proj.get('double')); @@ -283,7 +283,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZM Point geometries', function() { @@ -303,7 +303,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read LineString geometries', function() { @@ -341,7 +341,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZ LineString geometries', function() { @@ -362,7 +362,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYM LineString geometries', function() { @@ -383,7 +383,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZM LineString geometries', function() { @@ -404,7 +404,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read LinearRing geometries', function() { @@ -443,7 +443,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZ LinearRing geometries', function() { @@ -464,7 +464,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYM LinearRing geometries', function() { @@ -485,7 +485,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZM LinearRing geometries', function() { @@ -506,7 +506,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read Polygon geometries', function() { @@ -554,7 +554,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZ Polygon geometries', function() { @@ -581,7 +581,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYM Polygon geometries', function() { @@ -608,7 +608,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write XYZM Polygon geometries', function() { @@ -634,7 +634,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read complex Polygon geometries', function() { @@ -706,7 +706,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read MultiPoint geometries', function() { @@ -755,7 +755,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read MultiLineString geometries', function() { @@ -805,7 +805,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read MultiPolygon geometries', function() { @@ -873,7 +873,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can read empty GeometryCollection geometries', function() { @@ -1140,7 +1140,7 @@ describe('ol.format.KML', function() { ' My description' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write Feature\'s boolean attributes', function() { @@ -1160,7 +1160,7 @@ describe('ol.format.KML', function() { ' 0' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); }); @@ -1608,7 +1608,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write an feature\'s text style', function() { @@ -1640,7 +1640,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write an feature\'s stroke style', function() { @@ -1668,7 +1668,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); it('can write an feature\'s fill style', function() { @@ -1694,7 +1694,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); }); @@ -2210,7 +2210,7 @@ describe('ol.format.KML', function() { ' ' + ' ' + ''; - expect(node).to.xmleql(ol.xml.load(text)); + expect(node).to.xmleql(ol.xml.parse(text)); }); }); diff --git a/test/spec/ol/format/owsformat.test.js b/test/spec/ol/format/owsformat.test.js index d79c7439fb..03adf24096 100644 --- a/test/spec/ol/format/owsformat.test.js +++ b/test/spec/ol/format/owsformat.test.js @@ -7,7 +7,7 @@ describe('ol.format.OWS 1.1', function() { var parser = new ol.format.OWS(); it('should read ServiceProvider tag properly', function() { - var doc = ol.xml.load( + var doc = ol.xml.parse( '' + '' + @@ -56,7 +56,7 @@ describe('ol.format.OWS 1.1', function() { }); it('should read ServiceIdentification tag properly', function() { - var doc = ol.xml.load( + var doc = ol.xml.parse( '' + '' + @@ -86,7 +86,7 @@ describe('ol.format.OWS 1.1', function() { }); it('should read OperationsMetadata tag properly', function() { - var doc = ol.xml.load( + var doc = ol.xml.parse( '' + '' + diff --git a/test/spec/ol/format/wfsformat.test.js b/test/spec/ol/format/wfsformat.test.js index 3362c3877d..06f1686986 100644 --- a/test/spec/ol/format/wfsformat.test.js +++ b/test/spec/ol/format/wfsformat.test.js @@ -179,7 +179,7 @@ describe('ol.format.WFS', function() { srsName: 'urn:ogc:def:crs:EPSG::4326', propertyNames: ['STATE_NAME', 'STATE_FIPS', 'STATE_ABBR'] }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('creates paging headers', function() { @@ -204,7 +204,7 @@ describe('ol.format.WFS', function() { featurePrefix: 'topp', featureTypes: ['states'] }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); it('creates a BBOX filter', function() { @@ -231,7 +231,7 @@ describe('ol.format.WFS', function() { geometryName: 'the_geom', bbox: [1, 2, 3, 4] }); - expect(serialized.firstElementChild).to.xmleql(ol.xml.load(text)); + expect(serialized.firstElementChild).to.xmleql(ol.xml.parse(text)); }); }); @@ -247,7 +247,7 @@ describe('ol.format.WFS', function() { 'http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"/>'; var serialized = new ol.format.WFS().writeTransaction(null, null, null, {handle: 'handle_t'}); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -278,7 +278,7 @@ describe('ol.format.WFS', function() { featurePrefix: 'feature', gmlOptions: {multiCurve: true, srsName: 'EPSG:900913'} }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -309,7 +309,7 @@ describe('ol.format.WFS', function() { featurePrefix: 'foo', gmlOptions: {srsName: 'EPSG:900913'} }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -350,7 +350,7 @@ describe('ol.format.WFS', function() { featureType: 'states', featurePrefix: 'topp' }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -377,7 +377,7 @@ describe('ol.format.WFS', function() { value: 'Another native line goes here' }] }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); @@ -397,7 +397,7 @@ describe('ol.format.WFS', function() { featureTypes: ['states', 'cities'], featurePrefix: 'topp' }); - expect(serialized).to.xmleql(ol.xml.load(text)); + expect(serialized).to.xmleql(ol.xml.parse(text)); }); }); From ef435d9deb2507dbf7f9d8a83b062cc9ea8110d9 Mon Sep 17 00:00:00 2001 From: Antoine Abt Date: Mon, 27 Oct 2014 11:01:18 +0100 Subject: [PATCH 4/4] Improve doc for xml functions --- src/ol/xml.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ol/xml.js b/src/ol/xml.js index 249713fca2..8f7662da4d 100644 --- a/src/ol/xml.js +++ b/src/ol/xml.js @@ -77,8 +77,10 @@ ol.xml.createElementNS = /** + * Recursively grab all text content of child nodes into a single string. * @param {Node} node Node. - * @param {boolean} normalizeWhitespace Normalize whitespace. + * @param {boolean} normalizeWhitespace Normalize whitespace: remove all line + * breaks. * @return {string} All text content. * @api */ @@ -89,7 +91,8 @@ ol.xml.getAllTextContent = function(node, normalizeWhitespace) { /** * @param {Node} node Node. - * @param {boolean} normalizeWhitespace Normalize whitespace. + * @param {boolean} normalizeWhitespace Normalize whitespace: remove all line + * breaks. * @param {Array.} accumulator Accumulator. * @private * @return {Array.} Accumulator.