2 * @requires OpenLayers/Format/XML.js
4 * Class: OpenLayers.Format.WFSDescribeFeatureType
5 * Read WFS DescribeFeatureType response
8 * - <OpenLayers.Format.XML>
10 OpenLayers.Format.WFSDescribeFeatureType = OpenLayers.Class(
11 OpenLayers.Format.XML, {
14 * Property: namespaces
15 * {Object} Mapping of namespace aliases to namespace URIs.
18 xsd: "http://www.w3.org/2001/XMLSchema"
22 * Constructor: OpenLayers.Format.WFSDescribeFeatureType
23 * Create a new parser for WFS DescribeFeatureType responses.
26 * options - {Object} An optional object whose properties will be set on
29 initialize: function(options) {
30 OpenLayers.Format.XML.prototype.initialize.apply(this, [options]);
35 * Contains public functions, grouped by namespace prefix, that will
36 * be applied when a namespaced node is found matching the function
37 * name. The function will be applied in the scope of this parser
38 * with two arguments: the node being read and a context object passed
43 "schema": function(node, obj) {
44 var complexTypes = [];
47 complexTypes: complexTypes,
48 customTypes: customTypes
51 this.readChildNodes(node, schema);
53 var attributes = node.attributes;
55 for(var i=0, len=attributes.length; i<len; ++i) {
58 if(name.indexOf("xmlns") == 0) {
59 this.setNamespace(name.split(":")[1] || "", attr.value);
61 obj[name] = attr.value;
64 obj.featureTypes = complexTypes;
65 obj.targetPrefix = this.namespaceAlias[obj.targetNamespace];
67 // map complexTypes to names of customTypes
68 var complexType, customType;
69 for(var i=0, len=complexTypes.length; i<len; ++i) {
70 complexType = complexTypes[i];
71 customType = customTypes[complexType.typeName];
72 if(customTypes[complexType.typeName]) {
73 complexType.typeName = customType.name;
77 "complexType": function(node, obj) {
79 // this is a temporary typeName, it will be overwritten by
80 // the schema reader with the metadata found in the
82 "typeName": node.getAttribute("name")
84 this.readChildNodes(node, complexType);
85 obj.complexTypes.push(complexType);
87 "complexContent": function(node, obj) {
88 this.readChildNodes(node, obj);
90 "extension": function(node, obj) {
91 this.readChildNodes(node, obj);
93 "sequence": function(node, obj) {
97 this.readChildNodes(node, sequence);
98 obj.properties = sequence.elements;
100 "element": function(node, obj) {
103 var attributes = node.attributes;
105 for(var i=0, len=attributes.length; i<len; ++i) {
106 attr = attributes[i];
107 element[attr.name] = attr.value;
110 var type = element.type;
113 this.readChildNodes(node, type);
114 element.restriction = type;
115 element.type = type.base;
117 var fullType = type.base || type;
118 element.localType = fullType.split(":").pop();
119 obj.elements.push(element);
122 if(obj.complexTypes) {
123 var type = node.getAttribute("type");
124 var localType = type.split(":").pop();
125 obj.customTypes[localType] = {
126 "name": node.getAttribute("name"),
131 "simpleType": function(node, obj) {
132 this.readChildNodes(node, obj);
134 "restriction": function(node, obj) {
135 obj.base = node.getAttribute("base");
136 this.readRestriction(node, obj);
142 * Method: readRestriction
143 * Reads restriction defined in the child nodes of a restriction element
146 * node {DOMElement} - the node to parse
147 * obj {Object} - the object that receives the read result
149 readRestriction: function(node, obj) {
150 var children = node.childNodes;
151 var child, nodeName, value;
152 for(var i=0, len=children.length; i<len; ++i) {
154 if(child.nodeType == 1) {
155 nodeName = child.nodeName.split(":").pop();
156 value = child.getAttribute("value");
158 obj[nodeName] = value;
160 if(typeof obj[nodeName] == "string") {
161 obj[nodeName] = [obj[nodeName]];
163 obj[nodeName].push(value);
173 * data - {DOMElement|String} A WFS DescribeFeatureType document.
176 * {Object} An object representing the WFS DescribeFeatureType response.
178 read: function(data) {
179 if(typeof data == "string") {
180 data = OpenLayers.Format.XML.prototype.read.apply(this, [data]);
182 if(data && data.nodeType == 9) {
183 data = data.documentElement;
186 this.readNode(data, schema);
191 CLASS_NAME: "OpenLayers.Format.WFSDescribeFeatureType"