Read-in XML

Hi all

I've got a problem with reading in XML files into our system.
We use progress v10.1A, and I use the XML-Read in function. Everything seems to work, but there is one problem.
I'll try to explain in with an example:

<test>
<a>12345</a>
<b>aaaaa</b>
<c>a1b2c3</c>
</test>

in this case, I've got a temptable called test, with fields a,b,c. Import by read-in xml works fine.

but sometimes, the fields got an extra attribute:

<test>
<a>12345</a>
<b>aaaaa</b>
<c id="123">a1b2c3</c>
</test>

when I run my read-in xml, field c always has an empty value. And I want the values for a,b,c and id.

Could someone help me with this issue please?
 
Code:
    ASSIGN chInputfile              = tt-files.tt-full + "temp"
           chReadmode               = "EMPTY"
           chSchemaLocation         = ?
           loOverridedefaultmapping = TRUE
           chFieldtypemapping       = ? /*"email,CHAR"*/
           chVerifyschemamode       = ? /*"ignore"*/
           .

Code:
    loAns = DATASET AmazonEnvelope:READ-XML("FILE",
                                            chInputfile,
                                            chReadmode,               /* ReadMode */
                                            chSchemaLocation,         /* SchemaLocation*/
                                            loOverridedefaultmapping, /* overridedefaultmapping */
                                            chFieldtypemapping,       /* fieldtypemapping */
                                            chVerifyschemamode)       /* verifyschemamode */
                                            NO-ERROR.
 

GregTomkins

Active Member
Classic example of useless comments. (In the second snip; the first one could be a good example of useFUL comments).
 

Marian EDU

Member
<c id="123">a1b2c3</c>

when I run my read-in xml, field c always has an empty value. And I want the values for a,b,c and id.

that's because your field turns into a 'table', the dataset's read-xml method simply ignore that because you probably said so... otherwise if the schema do not match you should get an error, not empty string :)

so, no... unless you write your own parsing using SAX or DOM this won't work but why don't you define a schema and agree upon it with the other parties so there are no surprises like that. Once you have you contract, well schema, you can adapt the dataset accordingly and safely throw an error whenever anyone fails to comply to it... otherwise you might end-up with a nice garbage in/garbage out situation :)
 
Hi Marian

they defined a schema, but it doesnt seems to work. already used bproxsdto4gl / xsdto4gl command.
Already defined schema location, but always I'm getting errors like:

"Temp-Table 'OrderReport' not found in XML Schema. (13138)"
"Unable to parse schema for element 'AmazonOrderID'. (13134)"

they work with many clients, so they'll not change there XSD schema.

but I'll try to import it with SAX or DOM...
 

RealHeavyDude

Well-Known Member
Just my 2 cents:

The READ-XML function on a TEMP-TABLE or DATASET handle has been designed to be used with XML documents that were created with the WRITE-XML function in the first place. If your XML has not been created with WRITE-XML it's highly likely that the READ-XML function will fail. The only solution in that case is to implement your own logic based on the SAX or DOM parser. I always recommend the SAX parser.

Heavy Regards, RealHeavyDude.
 
Top