views:

39

answers:

0

Hi, 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"&gt;
<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?