6 Replies Latest reply on Feb 23, 2017 8:33 AM by DettCom

    Parsing XML

    DettCom Level 1

      Hello all,

       

      I am having a terrible time parsing an XML doc that is being returned from a service. I think it might be because I upgraded to CF11 and perhaps something is out of date.

       

      Normally I try to get this figured out myself but I just have spent too much time on something I'm sure is very easy.

       

      Here is what is being returned:

       

       

      <?xml version="1.0" encoding="utf-8"?>

      <WebServiceGeocodeResult version="4.10">

      <QueryMetadata>

      <TransactionId>512a8c85-8258-498c-88a2-c75289e3cb25</TransactionId>

      <Version>4.1</Version>

      <QueryStatusCodeValue>200</QueryStatusCodeValue>

      <FeatureMatchingResultType>Success</FeatureMatchingResultType>

      <FeatureMatchingResultCount>1</FeatureMatchingResultCount>

      <TimeTaken>0.0390039</TimeTaken>

      <ExceptionOccured>False</ExceptionOccured>

      <Exception />

      <ErrorMessage />

      </QueryMetadata>

      <InputAddress>

      <StreetAddress>1 S MAIN ST Akron OH 44308</StreetAddress>

      <City>Akron</City>

      <State>OH</State>

      <Zip>44308</Zip>

      </InputAddress>

      <OutputGeocodes>

      <OutputGeocode>

      <Latitude>41.0847797927252</Latitude>

      <Longitude>-81.5166029848824</Longitude>

      <NAACCRGISCoordinateQualityCode>02</NAACCRGISCoordinateQualityCode><NAACCRGISCoordinateQua lityType>Parcel</NAACCRGISCoordinateQualityType>

      <MatchScore>100</MatchScore>

      <MatchType>Exact</MatchType>

      <FeatureMatchingResultType>Success</FeatureMatchingResultType>

      <FeatureMatchingResultCount>1</FeatureMatchingResultCount>

      <FeatureMatchingGeographyType>Parcel</FeatureMatchingGeographyType>

      <RegionSize>553.366764519364</RegionSize>

      <RegionSizeUnits>Meters</RegionSizeUnits>

      <MatchedLocationType>LOCATION_TYPE_STREET_ADDRESS</MatchedLocationType>

      <ExceptionOccured>False</ExceptionOccured>

      <Exception />

      <ErrorMessage />

      </OutputGeocode>

      </OutputGeocodes>

      </WebServiceGeocodeResult>

       

       

      And here is the code that is parsing:

       

       

      Application.Functions.Dump(HTTPObject, "HTTPObject");

        //Remove everything before "<?xml"

        HTTPContent = Trim(ReReplace(HTTPObject.FileContent, "^.*(<\?xml)", "\1", "All"));

       

       

       

        /* Error responses*/

        // Bad request. The parameters passed to the service did not match as expected. The Message should tell you what was missing or incorrect.

        if(HTTPObject.QueryMetadata.QueryStatusCodeValue eq 400)

        {

        if(IsDefined("xmlDoc.Error.Message"))

        {

        throwGeocodeErrorMessage(xmlDoc.Error.Message.XmlText);

        }

        else

        {

        throwGeocodeFailed("Could not find required XML fields. XML: '" & HTTPContent & "'");

        }

        }

        xmlDoc = XmlParse(HTTPContent);

       

       

        if (HTTPObject.QueryMetadata.QueryStatusCodeValue neq 200)

        {

        throwGeocodeFailed("Error status code returned. Status Code: '" & HTTPObject.Responseheader.Status_Code &

        "'. XML: '" & HTTPContent & "'");

        }

        // Make sure all the required fields are available

        else if(Not (

        IsDefined("xmlDoc.WebServiceGeocodeResult.QueryStatusCodeValue") and

        IsDefined("xmlDoc.WebServiceGeocodeResult.Latitude") and

        IsDefined("xmlDoc.WebServiceGeocodeResult.Longitude") and

        IsDefined("xmlDoc.WebServiceGeocodeResult.MatchedLocationType")

        )

        )

        {

        throwGeocodeFailed("Could not find required XML fields. XML: '" & HTTPContent & "'");

        }

       

        //Make sure the response is 200(Success)

        if(xmlDoc.WebServiceGeocodeResult.QueryStatusCodeValue.XmlText neq "200")

        {

        throwGeocodeFailed("QueryStatusCodeValue: '" & xmlDoc.WebServiceGeocodeResult.QueryStatusCodeValue.XmlText  &

        "' QueryStatusCodeName: '" & xmlDoc.WebServiceGeocodeResult.QueryStatusCodeName.XmlText  &

        "'. XML: '" & HTTPContent & "'");

        }

       

       

      I think the issue is here: HTTPContent = Trim(ReReplace(HTTPObject.FileContent, "^.*(<\?xml)", "\1", "All"));

       

      Because I am getting errors that suggests that nothing is being parsed properly:

       

      Element QUERYMETADATA.QUERYSTATUSCODEVALUE is undefined in HTTPOBJECT.

       

      Any help would be greatly appreciated!!!

       

      Thanks.