I get the following XML back from an ASP-NET webservice (that alone took me 3 days). But because I’m such an XML nube, I don’t know how to format it into a basic display table. I need it to be in coldfusion because that’s all I understand and my site is a CF site. It uses diffgram which I also know nothing about. But, I’m ready to learn!
<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soap:Body>
<BillingResponse xmlns="http://portal/customer.asmx">
<BillingResult>
<xs:schema id="NewDataSet" xmlns="" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element msdata:IsDataSet="true" msdata:UseCurrentLocale="true" name="NewDataSet">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element name="Table">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="CustomerCode" type="xs:int"/>
<xs:element minOccurs="0" name="ServiceCode" type="xs:int"/>
<xs:element minOccurs="0" name="SubscriberCode" type="xs:string"/>
<xs:element minOccurs="0" name="Status" type="xs:string"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<NewDataSet xmlns="">
<Table diffgr:id="Table1" msdata:rowOrder="0">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>0</ServiceCode>
<SubscriberCode/>
<Status/>
</Table>
<Table diffgr:id="Table2" msdata:rowOrder="1">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>2</ServiceCode>
<SubscriberCode>95205292</SubscriberCode>
<Status>OPEN</Status>
</Table>
<Table diffgr:id="Table3" msdata:rowOrder="2">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>8</ServiceCode>
<SubscriberCode>dageorgetti</SubscriberCode>
<Status>1</Status>
</Table>
<Table diffgr:id="Table4" msdata:rowOrder="3">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>16</ServiceCode>
<SubscriberCode>NTL00711</SubscriberCode>
<Status>CLOSED</Status>
</Table>
<Table diffgr:id="Table5" msdata:rowOrder="4">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>16</ServiceCode>
<SubscriberCode>95205292</SubscriberCode>
<Status>CLOSED</Status>
</Table>
<Table diffgr:id="Table6" msdata:rowOrder="5">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>16</ServiceCode>
<SubscriberCode>95205292</SubscriberCode>
<Status>OPEN</Status>
</Table>
<Table diffgr:id="Table7" msdata:rowOrder="6">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>4096</ServiceCode>
<SubscriberCode>64280452637</SubscriberCode>
<Status>OPEN</Status>
</Table>
<Table diffgr:id="Table8" msdata:rowOrder="7">
<CustomerCode>1114309</CustomerCode>
<ServiceCode>4096</ServiceCode>
<SubscriberCode>64280426643</SubscriberCode>
<Status>OPEN</Status>
</Table>
</NewDataSet>
</diffgr:diffgram>
</BillingResult>
</BillingResponse>
</soap:Body>
</soap:Envelope>
Any code snippet or help through this horror show would be greatly appreciated
Normally when consuming a SOAP webservice from ColdFusion you would use
<cfinvoke>and things would come back in a close-to-native format.However, and especially when consuming ASP.NET ASMX webservices, I’ve found that the returned XML and ColdFusion’s parser don’t always play nice; so I tend to do the processing manually.
This code is from a method I wrote to make API calls. First, make the HTTP request manually:
Then check for common error conditions: (you may run into some-of/all-of/none-of/more-than these)
Then, parse the returned xml, and return just the part you’re interested in:
This would return the
<BillingResponse>node and everything inside it.Then you need to parse that for the data you need. You could do it with XPath expressions and the
XMLSearchfunction, or if the data is simple, just grab it manually.The DiffGram xml you reference is probably because you’re returning a DataTable object in your .Net code. Here’s how I handle that in ColdFusion:
First make sure there are child elements to get:
Then get the array of child elements:
In my case, I’m creating a query, so I add enough rows to the query to hold all of the data:
Then loop over each node in the array of child elements, copying the value to the query. The variable
local.fieldListis a list of xml nodes inside each row in your DataTable, and it will use the list to get each field. The outer loop iterates over the rows in the DataTable, and the inner loop iterates over the columns in the row. I’ve lopped off a lot from my list to keep the code relatively small, but there’s no problem with making the list large.Oh, and this also assumes that the field names in your DataTable are exactly the same as the column names in the query that it’s copying them to.