我正在尝试使用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>
我有两个问题:
在我的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 ?