Answered Parsing XML into a temp table

Tracy Hall

New Member
I don't know why I get so confused by this. When parsing a xml file in sax, do you have to have a temp-table field for each incoming piece of data? I am getting the error: Invalid handle. Not initialized or points to a deleted object. (3135) I am pretty sure it has to do with the way I am handling the value qName and attributeID then grabbing the text. Not sure how to fix it though.

Code:
<?xml version="1.0" encoding="UTF-8"?>
-<STEP-ProductInformation>-<Products>-<Product ID="134025" AnalyzerResult="included" ParentID="MM89542" UserTypeID="Item"><Name>101574</Name><ClassificationReference AnalyzerResult="" ClassificationID="" InheritedFrom=""/>-<Values><Value AttributeID="Caliber">.22 LR</Value><Value AttributeID="Diameter">1 Inch</Value><Value AttributeID="Thread">1/2-20 European</Value><Value AttributeID="Weight Ounce">3.4</Value><Value AttributeID="Catalog Vendor Name">AAC</Value><Value AttributeID="InventoryTyp">REG</Value><Value AttributeID="Item Class">02066</Value><Value AttributeID="Item Code">101574</Value><Value AttributeID="Item Description">AAC AAC PILOT 22LR 1/2-20</Value><Value AttributeID="Item Group">02</Value><Value AttributeID="Item Status">OPEN</Value><Value AttributeID="Primary Vendor">10440</Value><Value AttributeID="Retail Price">350.00</Value><Value AttributeID="Wildcat Eligible">N</Value><Value AttributeID="Consumer Description">Pilot Rimfire Silencer .22LR 5.25 Inches 1/2-20 European TPI Thread T3 Hard Coat Scarmor Finish - All NFA Rules Apply</Value><Value AttributeID="Length/Added">5.25 in./4.75 in.</Value><Value AttributeID="ProductPageNumber"><NoVersionPageNo/></Value><Value AttributeID="Master Model Header">Pilot 1/2-20 European</Value><Value AttributeID="Master Model Body Copy">Durable compact and light weight .22LR muzzle silencer for pistols and rifles. Stainless thread interface provides longevity and rigid mounting for improved accuracy with minimal and repeatable zero-shift. T3 Hard Coat Scarmor finish. Weight: 3.4 ounces. Length: 5.25 inches. Diameter: 1.0 inch. Mount: 1/2-20 European thread count. All NFA rules apply.</Value><Value AttributeID="Vendor Group">AAC</Value></Values><AssetCrossReference AnalyzerResult="included" AssetID="AAC_101574" Type="Primary Image"/></Product>[code]
 

Attachments

  • SaxProdHandler.p
    6.7 KB · Views: 7
  • saxProdParser.p
    1.1 KB · Views: 6

Stefan

Well-Known Member
I don't know why I get so confused by this. When parsing a xml file in sax, do you have to have a temp-table field for each incoming piece of data? I am getting the error: Invalid handle. Not initialized or points to a deleted object. (3135) I am pretty sure it has to do with the way I am handling the value qName and attributeID then grabbing the text. Not sure how to fix it though.

Your XML file contains silly things, corrected (and pretty printed with Notepad++ - which is not necessary for the actual import, but which does make it easier on humans) it is:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<Products>
    <Product ID="134025" AnalyzerResult="included" ParentID="MM89542" UserTypeID="Item">
        <Name>101574</Name>
        <ClassificationReference AnalyzerResult="" ClassificationID="" InheritedFrom=""/>
        <Values>
            <Value AttributeID="Caliber">.22 LR</Value>
            <Value AttributeID="Diameter">1 Inch</Value>
            <Value AttributeID="Thread">1/2-20 European</Value>
            <Value AttributeID="Weight Ounce">3.4</Value>
            <Value AttributeID="Catalog Vendor Name">AAC</Value>
            <Value AttributeID="InventoryTyp">REG</Value>
            <Value AttributeID="Item Class">02066</Value>
            <Value AttributeID="Item Code">101574</Value>
            <Value AttributeID="Item Description">AAC AAC PILOT 22LR 1/2-20</Value>
            <Value AttributeID="Item Group">02</Value>
            <Value AttributeID="Item Status">OPEN</Value>
            <Value AttributeID="Primary Vendor">10440</Value>
            <Value AttributeID="Retail Price">350.00</Value>
            <Value AttributeID="Wildcat Eligible">N</Value>
            <Value AttributeID="Consumer Description">Pilot Rimfire Silencer .22LR 5.25 Inches 1/2-20 European TPI Thread T3 Hard Coat Scarmor Finish - All NFA Rules Apply</Value>
            <Value AttributeID="Length/Added">5.25 in./4.75 in.</Value>
            <Value AttributeID="ProductPageNumber">
                <NoVersionPageNo/>
            </Value>
            <Value AttributeID="Master Model Header">Pilot 1/2-20 European</Value>
            <Value AttributeID="Master Model Body Copy">Durable compact and light weight .22LR muzzle silencer for pistols and rifles. Stainless thread interface provides longevity and rigid mounting for improved accuracy with minimal and repeatable zero-shift. T3 Hard Coat Scarmor finish. Weight: 3.4 ounces. Length: 5.25 inches. Diameter: 1.0 inch. Mount: 1/2-20 European thread count. All NFA rules apply.</Value>
            <Value AttributeID="Vendor Group">AAC</Value>
        </Values>
        <AssetCrossReference AnalyzerResult="included" AssetID="AAC_101574" Type="Primary Image"/>
    </Product>
</Products>

In the EndElement procedure you are always attempting to assign the value to a temp-table field with the name of the element. Values and Value are both elements in your XML so result in the error. There are multiple ways of handling this:

1. change hDBFld:BUFFER-VALUE = currentFieldValue to hDBFld:BUFFER-VALUE = currentFieldValue NO-ERROR.

2. check if the field with the element name exists in the temp-table - you can create a list of the fields in the temp-table (see :NUM-FIELDS and :BUFFER-FIELD(n):

Code:
DEFINE TEMP-TABLE tt
   FIELD aa AS CHAR
   FIELD bb AS CHAR
   .

DEF VAR hb AS HANDLE.
DEF VAR ii AS INT.

hb = TEMP-TABLE tt:DEFAULT-BUFFER-HANDLE.

DO ii = 1 TO hb:NUM-FIELDS:

   MESSAGE hb:BUFFER-FIELD( ii ):NAME VIEW-AS ALERT-BOX.

END.

3. only attempt to assign the value if there is a value
 
Top