Best Way To Read XML Data

kirsch59

Member
Below is an XML file that I would like to parse and possibly store in a temp-table. What are my options? Should I define a dataset and use READ-XML? How would I define the prodataset?


- <GetCustomerPricingResponse xmlns="http://tempuri.org/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
- <GetCustomerPricingResult xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:Errors><a:Errors />
<a:ResponseType>Success</a:ResponseType>
- <a:Result>
- <a:CustomerPrice>
- <a:Pricing>
- <a:PriceRecord>
<a:Price>123</a:Price>
<a:Quantity>1</a:Quantity>
<a:SiteId>0</a:SiteId>
</a:PriceRecord>

- <a:PriceRecord>
<a:Price>100</a:Price>
<a:Quantity>3</a:Quantity>
<a:SiteId>0</a:SiteId>
</a:PriceRecord>

- <a:PriceRecord>
<a:Price>143</a:Price>
<a:Quantity>1</a:Quantity>
<a:SiteId>1</a:SiteId>
</a:PriceRecord>

- <a:PriceRecord>
<a:Price>110</a:Price>
<a:Quantity>3</a:Quantity>
<a:SiteId>1</a:SiteId>
</a:PriceRecord>

</a:Pricing>

<a:ProductId>10</a:ProductId>
<a:Cono>2</a:Cono>
<a:CustomerId>12345</a:CustomerId>
</a:CustomerPrice>
</a:Result>
</GetCustomerPricingResult>
</GetCustomerPricingResponse>


I ran bprowsdldoc and got the following definitions:
<ns0:GetCustomerPricingResponse xmlns:ns0="http://tempuri.org/">
<!-- The following element is optional.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns0:GetCustomerPricingResult>
<!-- The following element is optional.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:Errors xmlns:ns1="http://schemas.datacontract.org/2004/07/CICWebservices.Common">
<!-- The following element may occur 0 or more times.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:Error>
<!-- The following element is optional.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:Message>string-value</ns1:Message>
<!-- The following element is optional. -->
<!-- This element must contain one of the following values:
Informational
Warning
Error -->
<ns1:Type>string-value</ns1:Type>
</ns1:Error>
</ns1:Errors>
<!-- The following element is optional. -->
<!-- This element must contain one of the following values:
Failure
Warning
Success -->
<ns1:ResponseType>string-value</ns1:ResponseType>
<!-- The following element is optional.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:Result>
<!-- The following element may occur 0 or more times.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:CustomerPrice>
<!-- The following element is optional.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:Pricing>
<!-- The following element may occur 0 or more times.
The following element may have the 'xsi:nil="true"` attribute (it is nillable). -->
<ns1:PriceRecord>
<!-- The following element is optional. -->
<ns1:Price>double-value</ns1:Price>
<!-- The following element is optional. -->
<ns1:Quantity>int-value</ns1:Quantity>
<!-- The following element is optional. -->
<ns1:SiteId>int-value</ns1:SiteId>
</ns1:PriceRecord>
</ns1:Pricing>
<!-- The following element is optional. -->
<ns1:ProductId>int-value</ns1:ProductId>
<!-- The following element is optional. -->
<ns1:Cono>int-value</ns1:Cono>
<!-- The following element is optional. -->
<ns1:CustomerId>int-value</ns1:CustomerId>
</ns1:CustomerPrice>
</ns1:Result>
</ns0:GetCustomerPricingResult>
</ns0:GetCustomerPricingResponse>

Lastly, I do not have the XML schema (.xsd) so I cannot run bproxsdto4gl. Your help is appreciated.
 
You don't mention version, but your mention of READ-XML suggests your version is reasonable modern. If so, you have three options:
1. Use DOM operators
2. Use the SAX-READER
3. Use READ-XML

DOM is the most work and slow for large files. SAX-READER is less work, very fast, and will do any size file. READ-XML is the ultimate in convenience, but doesn't work for all cases.

xsd files are easily created with tools, such as Stylus Studio, which I highly recommend if you are going to be doing much XML work.

At quick glance, you aren't going to get this to go into a temp-table because there is a hierarchy
Code:
CustomerPricingResponse
   CustomerPricingResult
      Errors
      ResponseType
      Result
         CustomerPricing
            Pricing
               PriceRecord  (multiple)
            ProductID
            Cono
            CustomerID
Now, that is a fairly complex data set and, from what you show, only the PriceRecord is a repeating group, i.e., something which really needs a temp-table, so you might be best using a SAX-READER to parse it.
 
Back
Top