diff --git a/src/ol/format/xmlformat.js b/src/ol/format/xmlformat.js index 2fd8ddbc54..e957102d82 100644 --- a/src/ol/format/xmlformat.js +++ b/src/ol/format/xmlformat.js @@ -1,6 +1,8 @@ goog.provide('ol.format.XML'); +goog.require('goog.array'); goog.require('goog.asserts'); +goog.require('goog.dom.NodeType'); goog.require('goog.dom.xml'); goog.require('ol.format.Format'); goog.require('ol.format.FormatType'); @@ -17,57 +19,6 @@ ol.format.XML = function() { goog.inherits(ol.format.XML, ol.format.Format); -/** - * @param {Document|Node|Object|string} source Source. - * @private - * @return {Document} Document. - */ -ol.format.XML.prototype.getDocument_ = function(source) { - if (source instanceof Document) { - return source; - } else if (goog.isString(source)) { - return goog.dom.xml.loadXml(source); - } else { - goog.asserts.fail(); - return null; - } -}; - - -/** - * @param {Document|Node|Object|string} source Source. - * @private - * @return {Document|Node} Document. - */ -ol.format.XML.prototype.getDocumentOrNode_ = function(source) { - if (source instanceof Document) { - return source; - } else if (source instanceof Node) { - return source; - } else if (goog.isString(source)) { - return goog.dom.xml.loadXml(source); - } else { - goog.asserts.fail(); - return null; - } -}; - - -/** - * @param {Document|Node|Object|string} source Source. - * @private - * @return {Node} Node. - */ -ol.format.XML.prototype.getNode_ = function(source) { - if (source instanceof Node) { - return source; - } else { - goog.asserts.fail(); - return null; - } -}; - - /** * @inheritDoc */ @@ -80,7 +31,31 @@ ol.format.XML.prototype.getType = function() { * @inheritDoc */ ol.format.XML.prototype.readFeature = function(source) { - return this.readFeatureFromNode(this.getNode_(source)); + if (source instanceof Document) { + return this.readFeatureFromDocument(source); + } else if (source instanceof Node) { + return this.readFeatureFromNode(source); + } else if (goog.isString(source)) { + var doc = goog.dom.xml.loadXml(source); + return this.readFeatureFromDocument(doc); + } else { + goog.asserts.fail(); + return null; + } +}; + + +/** + * @param {Document} doc Document. + * @return {ol.Feature} Feature. + */ +ol.format.XML.prototype.readFeatureFromDocument = function(doc) { + var features = this.readFeaturesFromDocument(doc); + if (features.length > 0) { + return features[0]; + } else { + return null; + } }; @@ -95,11 +70,13 @@ ol.format.XML.prototype.readFeatureFromNode = goog.abstractMethod; * @inheritDoc */ ol.format.XML.prototype.readFeatures = function(source) { - var documentOrNode = this.getDocumentOrNode_(source); - if (documentOrNode instanceof Document) { - return this.readFeaturesFromDocument(documentOrNode); - } else if (documentOrNode instanceof Node) { - return this.readFeaturesFromNode(documentOrNode); + if (source instanceof Document) { + return this.readFeaturesFromDocument(source); + } else if (source instanceof Node) { + return this.readFeaturesFromNode(source); + } else if (goog.isString(source)) { + var doc = goog.dom.xml.loadXml(source); + return this.readFeaturesFromDocument(doc); } else { goog.asserts.fail(); return null; @@ -113,8 +90,15 @@ ol.format.XML.prototype.readFeatures = function(source) { * @return {Array.