comparison pkg/wfs/capabilities.go @ 1602:e80e35b26f17

WFS Capabilities parser: Wrote a custom xml.Unmarshaler to extract the namespaces of FeatureTypes, too. They are needed in GetFeature requests.
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 17 Dec 2018 13:01:58 +0100
parents 658c1ebc1707
children 427f9010b4a9
comparison
equal deleted inserted replaced
1601:b88cc5aadcc1 1602:e80e35b26f17
109 109
110 type FeatureType struct { 110 type FeatureType struct {
111 XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 FeatureType"` 111 XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 FeatureType"`
112 Name string `xml:"Name"` 112 Name string `xml:"Name"`
113 Title string `xml:"Title"` 113 Title string `xml:"Title"`
114 Abstract string `xml:"Abstract"`
114 Keywords Keywords `xml:"Keywords"` 115 Keywords Keywords `xml:"Keywords"`
115 DefaultCRS string `xml:"DefaultCRS"` 116 DefaultCRS string `xml:"DefaultCRS"`
116 OtherCRSs []string `xml:"OtherCRS"` 117 OtherCRSs []string `xml:"OtherCRS"`
117 WGS84BoundingBox *WGS84BoundingBox `xml:"WGS84BoundingBox"` 118 WGS84BoundingBox *WGS84BoundingBox `xml:"WGS84BoundingBox"`
119 Namespaces []xml.Name `xml:"-"`
120 }
121
122 // shadowFeatureType is used to prevent recursive UnmarshalXML for FeatureType.
123 type shadowFeatureType struct {
124 XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 FeatureType"`
125 Name string `xml:"Name"`
126 Title string `xml:"Title"`
127 Abstract string `xml:"Abstract"`
128 Keywords Keywords `xml:"Keywords"`
129 DefaultCRS string `xml:"DefaultCRS"`
130 OtherCRSs []string `xml:"OtherCRS"`
131 WGS84BoundingBox *WGS84BoundingBox `xml:"WGS84BoundingBox"`
132 Namespaces []xml.Name `xml:"-"`
133 }
134
135 func (ft *FeatureType) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
136 // Filter out the namespaces for this feature type.
137 var ns []xml.Name
138 for _, attr := range start.Attr {
139 if attr.Name.Space == "xmlns" {
140 ns = append(ns, xml.Name{Space: attr.Name.Local, Local: attr.Value})
141 }
142 }
143 var sft shadowFeatureType
144 if err := d.DecodeElement(&sft, &start); err != nil {
145 return err
146 }
147 *ft = FeatureType(sft)
148 ft.Namespaces = ns
149 return nil
118 } 150 }
119 151
120 type FeatureTypeList struct { 152 type FeatureTypeList struct {
121 XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 FeatureTypeList"` 153 XMLName xml.Name `xml:"http://www.opengis.net/wfs/2.0 FeatureTypeList"`
122 FeatureTypes []*FeatureType `xml:"FeatureType"` 154 FeatureTypes []*FeatureType `xml:"FeatureType"`