Merge pull request #2869 from tonio/xmlexport
Export useful xml functions
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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.<number>} */
|
||||
(goog.object.get(values, 'flatCoordinates'));
|
||||
var ends = /** @type {Array.<number>} */ (goog.object.get(values, 'ends'));
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -77,9 +77,12 @@ 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
|
||||
*/
|
||||
ol.xml.getAllTextContent = function(node, normalizeWhitespace) {
|
||||
return ol.xml.getAllTextContent_(node, normalizeWhitespace, []).join('');
|
||||
@@ -88,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.<String|string>} accumulator Accumulator.
|
||||
* @private
|
||||
* @return {Array.<String|string>} Accumulator.
|
||||
@@ -332,10 +336,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');
|
||||
};
|
||||
|
||||
@@ -641,7 +647,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];
|
||||
@@ -668,7 +674,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();
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user