Skip to main content
Gear_Head
Known Participant
October 30, 2009
Question

Web service need to save XML to a file

  • October 30, 2009
  • 1 reply
  • 3861 views

Hi,

I use a web service (use to be CFTTP and was working fine thanks to Ian Skinner) for a VIN decoder (Vehicle Identification Number) they charge per request and i can get all the car options in  3 language, they provided me with the CFM file i need to do the request and i got that part to work fine. but i need to save the XML result so i can have all the options on our server and not having to request it everytime we need to see it.

So this is the CFM that gets the vin from the web service. I need to know if it is possible to get the XML out of there and save it to a file.


<cffunction name="isNull" returntype="string" output="false">
    <cfargument name="test" type="variableName" required="Yes">
    <cfif isDefined(test)>
        <cfreturn Evaluate(test)>
    <cfelse>
        <cfreturn "">
    </cfif>
</cffunction>

<cfscript>

    webService = createObject("webservice", "MY_VIN_WS");

countryCode = "US";
    languageCode = "en";
if( IsDefined("url.countryCode") ){
  countryCode = url.countryCode;
} else {
  countryCode = "US";
}
if( IsDefined("url.languageCode") ){
  languageCode = url.languageCode;
} else {
  languageCode = "en";
}
if( languageCode EQ "es" AND countryCode EQ "CA" ){
  languageCode = "en";
}
if( languageCode EQ "fr" AND countryCode EQ "US" ){
  languageCode = "en";
}

    accountInfo = StructNew();
    accountInfo.accountNumber = "MY_ACCOUNTx";
    accountInfo.accountSecret = "MY_PASSWORD";
    accountInfo.locale = StructNew();
    accountInfo.locale.language = languageCode;
    accountInfo.locale.country = countryCode;

    version = "";
    dataVersionsRequest = StructNew();
    dataVersionsRequest.accountInfo = accountInfo;
    dataVersions = webService.getDataVersions(dataVersionsRequest);
    for (i = 1; i LTE ArrayLen(dataVersions); i=i+1) {
        if (dataVersions.country EQ "US"){
            version = dataVersions.country & " " & dataVersions.build & " (" & DateFormat(dataVersions.date) & " " & TimeFormat(dataVersions.date) & ")";
        }
    }

</cfscript>
<cfif IsDefined("url.vin")>
    <cfscript>

  returnParameters = StructNew();
        returnParameters.useSafeStandards = IsDefined("url.useSafeStandards");
        returnParameters.excludeFleetOnlyStyles = IsDefined("url.excludeFleetOnlyStyles");
        returnParameters.includeAvailableEquipment = IsDefined("url.includeAvailableEquipment");
        returnParameters.includeExtendedDescriptions = IsDefined("url.includeExtendedDescriptions");
        returnParameters.includeExtendedTechnicalSpecifications = IsDefined("url.includeExtendedTechnicalSpecifications");
        returnParameters.includeRegionSpecificStyles = IsDefined("url.includeRegionSpecificStyles");
        returnParameters.includeConsumerInformation = IsDefined("url.includeConsumerInformation");
  returnParameters.enableEnrichedVehicleEquipment = false;

        vinRequest = StructNew();
        vinRequest.accountInfo = accountInfo;
        vinRequest.vin = url.vin;
        vinRequest.manufacturerModelCode = url.manufacturerModelCode;
        vinRequest.trimName = url.trimName;
        vinRequest.wheelBase = val("url.wheelBase");
        vinRequest.manufacturerOptionCodes = ListToArray(url.manufacturerOptionCodes, ",");
        vinRequest.equipmentDescriptions = ListToArray(url.equipmentDescriptions, ",");
        vinRequest.secondaryEquipmentDescriptions = ListToArray(url.secondaryEquipmentDescriptions, ",");
        vinRequest.exteriorColorName = url.exteriorColorName;
  vinRequest.returnParameters = returnParameters;

        vehicleInfo = webService.getVehicleInformationFromVin(vinRequest);

  showInstallCause = IsDefined("url.includeCauseChain");
    </cfscript>
</cfif>

I also attach the entire file if you need to see it

Help would be greatly appreciated

This topic has been closed for replies.

1 reply

ilssac
Inspiring
October 30, 2009

There may not be an XML for you to save.  That would depend on what features the builders of the web service have provided in their API.  If there is a function in the web service that returns the data in an XML format then that is what you would use, if this does not exist you will have to do it manually.

If XML is the goal and a function does not exist to get it, you would just create your own XML format, calling the various functions on the web service API to get the desired data for each node of your XML document.

If just persisting the object is the goal, you may want to look at the <cfwddx....> tag and|or serialization of the obect you received from the web service.

Gear_Head
Gear_HeadAuthor
Known Participant
October 30, 2009

Is there a way i can save the result in an HTML file then ?

Inspiring
October 30, 2009

Like Ian said, it depends on what they give you. Either look through the web service provider docs or do a cfdump of the webservice object. Look for any methods that may return the XML or HTML. If you find that, then saving that file is trivial because that data will be in the variable.