diff --git a/src/ol/format/gml/gmlbaseformat.js b/src/ol/format/gml/gmlbaseformat.js
index 3afda6975d..64d0fe914d 100644
--- a/src/ol/format/gml/gmlbaseformat.js
+++ b/src/ol/format/gml/gmlbaseformat.js
@@ -111,7 +111,7 @@ ol.format.GMLBase.ONLY_WHITESPACE_RE_ = /^[\s\xa0]*$/;
ol.format.GMLBase.prototype.readFeaturesInternal = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- var localName = ol.xml.getLocalName(node);
+ var localName = node.localName;
var features;
if (localName == 'FeatureCollection') {
if (node.namespaceURI === 'http://www.opengis.net/wfs') {
@@ -219,7 +219,7 @@ ol.format.GMLBase.prototype.readFeatureElement = function(node, objectStack) {
ol.xml.getAttributeNS(node, ol.format.GMLBase.GMLNS, 'id');
var values = {}, geometryName;
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
- var localName = ol.xml.getLocalName(n);
+ var localName = n.localName;
// Assume attribute elements have one child node and that the child
// is a text or CDATA node (to be treated as text).
// Otherwise assume it is a geometry node.
diff --git a/src/ol/format/kmlformat.js b/src/ol/format/kmlformat.js
index 66dc5301b4..936ae8b294 100644
--- a/src/ol/format/kmlformat.js
+++ b/src/ol/format/kmlformat.js
@@ -1745,7 +1745,7 @@ ol.format.KML.prototype.getExtensions = function() {
ol.format.KML.prototype.readDocumentOrFolder_ = function(node, objectStack) {
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- var localName = ol.xml.getLocalName(node);
+ var localName = node.localName;
goog.asserts.assert(localName == 'Document' || localName == 'Folder',
'localName should be Document or Folder');
// FIXME use scope somehow
@@ -1923,7 +1923,7 @@ ol.format.KML.prototype.readFeaturesFromNode = function(node, opt_options) {
return [];
}
var features;
- var localName = ol.xml.getLocalName(node);
+ var localName = node.localName;
if (localName == 'Document' || localName == 'Folder') {
features = this.readDocumentOrFolder_(
node, [this.getReadOptions(node, opt_options)]);
@@ -2009,7 +2009,7 @@ ol.format.KML.prototype.readNameFromNode = function(node) {
}
}
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
- var localName = ol.xml.getLocalName(n);
+ var localName = n.localName;
if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
(localName == 'Document' ||
localName == 'Folder' ||
@@ -2080,7 +2080,7 @@ ol.format.KML.prototype.readNetworkLinksFromNode = function(node) {
}
}
for (n = node.firstElementChild; n; n = n.nextElementSibling) {
- var localName = ol.xml.getLocalName(n);
+ var localName = n.localName;
if (ol.array.includes(ol.format.KML.NAMESPACE_URIS_, n.namespaceURI) &&
(localName == 'Document' ||
localName == 'Folder' ||
diff --git a/src/ol/format/wmsgetfeatureinfoformat.js b/src/ol/format/wmsgetfeatureinfoformat.js
index 6b669742a6..f8437b91bd 100644
--- a/src/ol/format/wmsgetfeatureinfoformat.js
+++ b/src/ol/format/wmsgetfeatureinfoformat.js
@@ -75,7 +75,7 @@ ol.format.WMSGetFeatureInfo.prototype.readFeatures_ = function(node, objectStack
node.setAttribute('namespaceURI', this.featureNS_);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- var localName = ol.xml.getLocalName(node);
+ var localName = node.localName;
/** @type {Array.
} */
var features = [];
if (node.childNodes.length === 0) {
diff --git a/src/ol/format/xmlfeatureformat.js b/src/ol/format/xmlfeatureformat.js
index cbee017f33..dbb742afde 100644
--- a/src/ol/format/xmlfeatureformat.js
+++ b/src/ol/format/xmlfeatureformat.js
@@ -2,7 +2,6 @@ goog.provide('ol.format.XMLFeature');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
-goog.require('goog.dom.xml');
goog.require('ol.array');
goog.require('ol.format.Feature');
goog.require('ol.format.FormatType');
@@ -20,6 +19,13 @@ goog.require('ol.xml');
* @extends {ol.format.Feature}
*/
ol.format.XMLFeature = function() {
+
+ /**
+ * @type {XMLSerializer}
+ * @private
+ */
+ this.xmlSerializer_ = new XMLSerializer();
+
goog.base(this);
};
goog.inherits(ol.format.XMLFeature, ol.format.Feature);
@@ -206,7 +212,7 @@ ol.format.XMLFeature.prototype.writeFeature = function(feature, opt_options) {
var node = this.writeFeatureNode(feature, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- return goog.dom.xml.serialize(/** @type {Element} */(node));
+ return this.xmlSerializer_.serializeToString(node);
};
@@ -226,7 +232,7 @@ ol.format.XMLFeature.prototype.writeFeatures = function(features, opt_options) {
var node = this.writeFeaturesNode(features, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- return goog.dom.xml.serialize(/** @type {Element} */(node));
+ return this.xmlSerializer_.serializeToString(node);
};
@@ -245,7 +251,7 @@ ol.format.XMLFeature.prototype.writeGeometry = function(geometry, opt_options) {
var node = this.writeGeometryNode(geometry, opt_options);
goog.asserts.assert(node.nodeType == goog.dom.NodeType.ELEMENT,
'node.nodeType should be ELEMENT');
- return goog.dom.xml.serialize(/** @type {Element} */(node));
+ return this.xmlSerializer_.serializeToString(node);
};
diff --git a/src/ol/xml.js b/src/ol/xml.js
index 2d86b031b5..a3b772a568 100644
--- a/src/ol/xml.js
+++ b/src/ol/xml.js
@@ -2,8 +2,6 @@ goog.provide('ol.xml');
goog.require('goog.asserts');
goog.require('goog.dom.NodeType');
-goog.require('goog.dom.xml');
-goog.require('goog.userAgent');
goog.require('ol.array');
@@ -35,44 +33,19 @@ ol.xml.Serializer;
* @const
* @type {Document}
*/
-ol.xml.DOCUMENT = goog.dom.xml.createDocument();
+ol.xml.DOCUMENT = document.implementation.createDocument('', '', null);
/**
* @param {string} namespaceURI Namespace URI.
* @param {string} qualifiedName Qualified name.
* @return {Node} Node.
- * @private
*/
-ol.xml.createElementNS_ = function(namespaceURI, qualifiedName) {
+ol.xml.createElementNS = function(namespaceURI, qualifiedName) {
return ol.xml.DOCUMENT.createElementNS(namespaceURI, qualifiedName);
};
-/**
- * @param {string} namespaceURI Namespace URI.
- * @param {string} qualifiedName Qualified name.
- * @return {Node} Node.
- * @private
- */
-ol.xml.createElementNSActiveX_ = function(namespaceURI, qualifiedName) {
- if (!namespaceURI) {
- namespaceURI = '';
- }
- return ol.xml.DOCUMENT.createNode(1, qualifiedName, namespaceURI);
-};
-
-
-/**
- * @param {string} namespaceURI Namespace URI.
- * @param {string} qualifiedName Qualified name.
- * @return {Node} Node.
- */
-ol.xml.createElementNS =
- (document.implementation && document.implementation.createDocument) ?
- ol.xml.createElementNS_ : ol.xml.createElementNSActiveX_;
-
-
/**
* Recursively grab all text content of child nodes into a single string.
* @param {Node} node Node.
@@ -114,226 +87,57 @@ ol.xml.getAllTextContent_ = function(node, normalizeWhitespace, accumulator) {
};
-/**
- * @param {Node} node Node.
- * @private
- * @return {string} Local name.
- */
-ol.xml.getLocalName_ = function(node) {
- return node.localName;
-};
-
-
-/**
- * @param {Node} node Node.
- * @private
- * @return {string} Local name.
- */
-ol.xml.getLocalNameIE_ = function(node) {
- var localName = node.localName;
- if (localName !== undefined) {
- return localName;
- }
- var baseName = node.baseName;
- goog.asserts.assert(baseName,
- 'Failed to get localName/baseName of node %s', node);
- return baseName;
-};
-
-
-/**
- * @param {Node} node Node.
- * @return {string} Local name.
- */
-ol.xml.getLocalName = goog.userAgent.IE ?
- ol.xml.getLocalNameIE_ : ol.xml.getLocalName_;
-
-
/**
* @param {?} value Value.
- * @private
* @return {boolean} Is document.
*/
-ol.xml.isDocument_ = function(value) {
+ol.xml.isDocument = function(value) {
return value instanceof Document;
};
/**
* @param {?} value Value.
- * @private
- * @return {boolean} Is document.
- */
-ol.xml.isDocumentIE_ = function(value) {
- return goog.isObject(value) && value.nodeType == goog.dom.NodeType.DOCUMENT;
-};
-
-
-/**
- * @param {?} value Value.
- * @return {boolean} Is document.
- */
-ol.xml.isDocument = goog.userAgent.IE ?
- ol.xml.isDocumentIE_ : ol.xml.isDocument_;
-
-
-/**
- * @param {?} value Value.
- * @private
* @return {boolean} Is node.
*/
-ol.xml.isNode_ = function(value) {
+ol.xml.isNode = function(value) {
return value instanceof Node;
};
-/**
- * @param {?} value Value.
- * @private
- * @return {boolean} Is node.
- */
-ol.xml.isNodeIE_ = function(value) {
- return goog.isObject(value) && value.nodeType !== undefined;
-};
-
-
-/**
- * @param {?} value Value.
- * @return {boolean} Is node.
- */
-ol.xml.isNode = goog.userAgent.IE ? ol.xml.isNodeIE_ : ol.xml.isNode_;
-
-
/**
* @param {Node} node Node.
* @param {?string} namespaceURI Namespace URI.
* @param {string} name Attribute name.
* @return {string} Value
- * @private
*/
-ol.xml.getAttributeNS_ = function(node, namespaceURI, name) {
+ol.xml.getAttributeNS = function(node, namespaceURI, name) {
return node.getAttributeNS(namespaceURI, name) || '';
};
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @return {string} Value
- * @private
- */
-ol.xml.getAttributeNSActiveX_ = function(node, namespaceURI, name) {
- var attributeValue = '';
- var attributeNode = ol.xml.getAttributeNodeNS(node, namespaceURI, name);
- if (attributeNode !== undefined) {
- attributeValue = attributeNode.nodeValue;
- }
- return attributeValue;
-};
-
-
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @return {string} Value
- */
-ol.xml.getAttributeNS =
- (document.implementation && document.implementation.createDocument) ?
- ol.xml.getAttributeNS_ : ol.xml.getAttributeNSActiveX_;
-
-
/**
* @param {Node} node Node.
* @param {?string} namespaceURI Namespace URI.
* @param {string} name Attribute name.
* @return {?Node} Attribute node or null if none found.
- * @private
*/
-ol.xml.getAttributeNodeNS_ = function(node, namespaceURI, name) {
+ol.xml.getAttributeNodeNS = function(node, namespaceURI, name) {
return node.getAttributeNodeNS(namespaceURI, name);
};
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @return {?Node} Attribute node or null if none found.
- * @private
- */
-ol.xml.getAttributeNodeNSActiveX_ = function(node, namespaceURI, name) {
- var attributeNode = null;
- var attributes = node.attributes;
- var potentialNode, fullName;
- for (var i = 0, len = attributes.length; i < len; ++i) {
- potentialNode = attributes[i];
- if (potentialNode.namespaceURI == namespaceURI) {
- fullName = (potentialNode.prefix) ?
- (potentialNode.prefix + ':' + name) : name;
- if (fullName == potentialNode.nodeName) {
- attributeNode = potentialNode;
- break;
- }
- }
- }
- return attributeNode;
-};
-
-
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @return {?Node} Attribute node or null if none found.
- */
-ol.xml.getAttributeNodeNS =
- (document.implementation && document.implementation.createDocument) ?
- ol.xml.getAttributeNodeNS_ : ol.xml.getAttributeNodeNSActiveX_;
-
-
/**
* @param {Node} node Node.
* @param {?string} namespaceURI Namespace URI.
* @param {string} name Attribute name.
* @param {string|number} value Value.
- * @private
*/
-ol.xml.setAttributeNS_ = function(node, namespaceURI, name, value) {
+ol.xml.setAttributeNS = function(node, namespaceURI, name, value) {
node.setAttributeNS(namespaceURI, name, value);
};
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @param {string|number} value Value.
- * @private
- */
-ol.xml.setAttributeNSActiveX_ = function(node, namespaceURI, name, value) {
- if (namespaceURI) {
- var attribute = node.ownerDocument.createNode(2, name, namespaceURI);
- attribute.nodeValue = value;
- node.setAttributeNode(attribute);
- } else {
- node.setAttribute(name, value);
- }
-};
-
-
-/**
- * @param {Node} node Node.
- * @param {?string} namespaceURI Namespace URI.
- * @param {string} name Attribute name.
- * @param {string|number} value Value.
- */
-ol.xml.setAttributeNS =
- (document.implementation && document.implementation.createDocument) ?
- ol.xml.setAttributeNS_ : ol.xml.setAttributeNSActiveX_;
-
-
/**
* Parse an XML string to an XML Document.
* @param {string} xml XML.