xmlbean 和命名空间属性
我正在尝试使用 xmlbeans 来解析 Google 地理编码器 xml 响应。
我有一个 xsd,它定义了地理编码器返回的 KML 的子集。
这里有一个示例地理编码器响应供参考:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Response>
<name>520 3rd Street San Francisco CA</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>520 3rd St, San Francisco, CA 94107, USA</address>
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Country>
<CountryNameCode>US</CountryNameCode>
<CountryName>USA</CountryName>
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
<SubAdministrativeArea>
<SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName>
<Locality>
<LocalityName>San Francisco</LocalityName>
<Thoroughfare>
<ThoroughfareName>520 3rd St</ThoroughfareName>
</Thoroughfare>
<PostalCode>
<PostalCodeNumber>94107</PostalCodeNumber>
</PostalCode>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea>
</Country>
</AddressDetails>
<ExtendedData>
<LatLonBox north="37.7842288" south="37.7779335" east="-122.3924109" west="-122.3987062" />
</ExtendedData>
<Point>
<coordinates>-122.3955669,37.7810746,0</coordinates>
</Point>
</Placemark>
</Response>
</kml>
我有 2 个问题:
在我的 xsd 中,因为我想要 Accuracy 属性,所以我将 AddressDetails 定义为:
<?xml version="1.0" encoding="UTF-8"?>
<complexType name="placemark">
<sequence>
<element name="address" type="string" />
<element name="AddressDetails" type="ggc:addressDetails"/>
<element name="ExtendedData" type="ggc:extendedData" />
<element name="Point" type="ggc:point" />
</sequence>
</complexType>
<complexType name="addressDetails">
<sequence>
<element name="Country" type="string"/>
</sequence>
<attribute name="Accuracy" type="ggc:accuracy"/>
</complexType>
但是当我调用 placemark.getAddressDetails() 时 在生成的代码上它返回 null。我认为这是因为 AddressDetails 元素中的 xmlns 属性?但我不确定(其他吸气剂返回我所期望的)。我能做些什么吗?
其次,在我的 xsd 中,我必须将命名空间定义为 http://earth.google.com/kml/2.0 以匹配 Google 返回的内容,尽管我的 xsd 显然不是真正的 xsd。有什么方法可以覆盖 xmlbeans 中的标头处理,以便默认名称空间可以类似于 http://foo/baa 吗?
I'm trying to use xmlbeans to parse Google geocoder xml responses.
I have an xsd which defines a subset of the KML returned by the geocoder.
For reference here is an example geocoder response:
<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.0">
<Response>
<name>520 3rd Street San Francisco CA</name>
<Status>
<code>200</code>
<request>geocode</request>
</Status>
<Placemark id="p1">
<address>520 3rd St, San Francisco, CA 94107, USA</address>
<AddressDetails Accuracy="8" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
<Country>
<CountryNameCode>US</CountryNameCode>
<CountryName>USA</CountryName>
<AdministrativeArea>
<AdministrativeAreaName>CA</AdministrativeAreaName>
<SubAdministrativeArea>
<SubAdministrativeAreaName>San Francisco</SubAdministrativeAreaName>
<Locality>
<LocalityName>San Francisco</LocalityName>
<Thoroughfare>
<ThoroughfareName>520 3rd St</ThoroughfareName>
</Thoroughfare>
<PostalCode>
<PostalCodeNumber>94107</PostalCodeNumber>
</PostalCode>
</Locality>
</SubAdministrativeArea>
</AdministrativeArea>
</Country>
</AddressDetails>
<ExtendedData>
<LatLonBox north="37.7842288" south="37.7779335" east="-122.3924109" west="-122.3987062" />
</ExtendedData>
<Point>
<coordinates>-122.3955669,37.7810746,0</coordinates>
</Point>
</Placemark>
</Response>
</kml>
I have 2 questions:
In my xsd, as I want the Accuracy attribute, I define the AddressDetails as:
<?xml version="1.0" encoding="UTF-8"?>
<complexType name="placemark">
<sequence>
<element name="address" type="string" />
<element name="AddressDetails" type="ggc:addressDetails"/>
<element name="ExtendedData" type="ggc:extendedData" />
<element name="Point" type="ggc:point" />
</sequence>
</complexType>
<complexType name="addressDetails">
<sequence>
<element name="Country" type="string"/>
</sequence>
<attribute name="Accuracy" type="ggc:accuracy"/>
</complexType>
But when I call placemark.getAddressDetails() on the generated code it returns null. I think this because of the xmlns attribute in the AddressDetails element? but I'm not sure(The other getters return what I expect). Is there anything I can do about it?
Secondly, In my xsd I have to define the namespace as http://earth.google.com/kml/2.0 to match what's returned by Google, although the my xsd is clearly not the real xsd. Is there any way to override the header processing in xmlbeans so the default namespace can be something like http://foo/baa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论