forsms2002
17th February 2005, 02:27
I have an xml file like this:
<tdpur400><orno>INT001293</orno><otbp>SAM001001</otbp>
<tdpur401><pono>10</pono><item>UT512X14 </item><oqua>12</oqua>
<tdpur401><pono>20</pono><item>UT513X24 </item><oqua>12</oqua>
<tdpur400>....
<tdpur401>.... and so on
(there is NO header like <?xml version="1.0"? and <!DOCTYPE ABC "ABC.dtd"> )
I am to read this XML file and send it to report...as order,position,item,qty, etc
I have written below piece of code to read the file:
start
long fd
long cmfId, identId, fromId
long retVal
long found
string error_string(1000)
string xorno(20)
string xpono(20)
string xoqua(20)
|Open the XML file for reading.
fd = seq.open ("/tmp/po.xml", "r" )
|Parse the XML file
cmfId = xmlRead(fd, error_string)
seq.close(fd)
|Search for the tdpur400 element
identId = xmlFindFirst( "tdpur400", cmfId)
if (identId <> 0 )
then
|Get the attributes
retVal = xmlGetAttribute(identId, "xorno" ,xorno)
retVal = xmlGetAttribute(identId, "xpono", xpono)
retVal = xmlGetAttribute(identId, "xoqua", xoqua)
endif
end
the line xmlRead returns with the followinig error:
read.main.table.error_string="Line: 2;Col: 0; junk after document element"
am i using the wrong command? or is there another way to read the xml document.
Early reply would be highly appreciated.
Thanks
monica1
17th February 2005, 09:43
One time I did something similar and to solve the problem I add a columm in blank in each line. Try with it.
lbencic
17th February 2005, 16:45
We've read the xml files, but did things a little different. We did have to put in the heading line:
<rmctimecardin xmlns="http://tempuri.org/rmctimecardin1.xsd">
(tempuri.org is the sample given in Baan, it worked, but we later substitute our own.)
Apart from that our file is a little different from the approach you took, we use a format for the lines that looks like:
<trx type="empinfo" xmlns="" />
But then we read it a little different...
I think if you include the heading on the first line, you may get past the read, or you may require that xmlns="", we could not process without it, but that was after the read I think.
forsms2002
17th February 2005, 20:02
Our piece of code now looks like below:
xml.id = xmlread(fd, error_string)
seq.close(fd)
Line 1:tdpur400.id = xmlFindFirst("tdpur400",xml.id)
Line 2:while tdpur400.id <> 0
Line 3: ret.val = xmlGetDataElement(tdpur400.id,"xorno",xorno)
Line 4: tdpur401.id = xmlFindFirst("tdpur401",tdpur400.id)
Line 5: while tdpur401.id <> 0
Line 6: ret.val = xmlGetDataElement(tdpur401.id,"xpono",xpono)
Line 7: ret.val = xmlGetDataElement(tdpur401.id,"xitem",xitem)
Line 8: ret.val = xmlGetDataElement(tdpur401.id,"xoqua",xoqua)
Line 9: |* Check for another line.
Line10 : tdpur401.id = xmlGetRightSibling(tdpur401.id)
Line11: endwhile
Line12: tdpur400.id = xmlGetRightSibling(tdpur400.id)
Line13:endwhile
Our main aim is to first read header and than each of its detail lines and than new order...
When we execute, the order is something like below:
Line 3 returns xorno as expected
Line 4 returns 0 ...???
then we reach line 12 which returns non-zero
then again Line 3 and the pointer is still on the first order
then Line 4 returns non-zero and than xpono,xitem and xoqua is stored as expected
If this order has just 1 detail line, it must go to the next order header, but it continues with the next orders detail line till
the end of file.
Our guess is it is taking depth first traversal order..how to enforce breadth first traversal order...or is there other way to handle this?
lbencic
17th February 2005, 21:26
Can we see the file again? How did you get past the read statement error, what change did you make.
I am NO xml expert. But, I don't see the close of the tdpur400 record in the sample file you did post.
<tdpur400><orno>INT001293</orno><otbp>SAM001001</otbp>
<tdpur401><pono>10</pono><item>UT512X14 </item><oqua>12</oqua>
<tdpur401><pono>20</pono><item>UT513X24 </item><oqua>12</oqua>
<tdpur400>....
<tdpur401>.... and so on
Should this not have the </tdpur400> in there somewhere..? Probably after the last tdpur401 line that you want to include. The tdpur401's have no end either for that matter. The ones we use to read in Baan all have ends...
Also, just FYI, you can check how Baan interprets the file in the debugger, after the read is issued, by clicking on the xml.id variable. Maybe that will give some clues.
forsms2002
17th February 2005, 22:04
the file ends properly as below:
<?xml version="1.0"?>
<!DOCTYPE JDB "JDB.dtd">
<WEBC>
<tdpur400><orno>INT001293</orno><otbp>SAM001001</otbp></tdpur400>
<tdpur401><pono>10</pono><item>UT512X14 </item><oqua>12</oqua></tdpur401>
<tdpur401><pono>20</pono><item>UT513X24 </item><oqua>12</oqua></tdpur401>
<tdpur400>.2nd order...</tdpur400>
<tdpur401>.2nd order line 1</tdpur401>
<tdpur401>.2nd order line 2</tdpur401>
... and so on
</WEBC>
I am now able to read the XML file as I have added the first two lines viz.
<?xml ver..etc?>.
Still the problem of
1. Line4 returning zero first time and
2. than second time the entire file is read for the first purchase order
3. why is the function tdpur401.id = xmlGetRightSibling(tdpur401.id) at line 10 not returning zero when a new order starts..
thanks ...
lbencic
17th February 2005, 22:16
I think to read the tdpur401's as a 'child' of tdpur400, you need to end the tdpur400 after the last associated tdpur401 line. Like:
<tdpur400><orno>INT001293</orno><otbp>SAM001001</otbp>
<tdpur401><pono>10</pono><item>UT512X14 </item><oqua>12</oqua></tdpur401>
<tdpur401><pono>20</pono><item>UT513X24 </item><oqua>12</oqua></tdpur401></tdpur400>
forsms2002
17th February 2005, 22:28
Thanks a lot lbencic. It works ..
But my problem is , I receive the XML file in that format only. So is there no way out here? or I have to change the file format after I receive it.????
lbencic
17th February 2005, 22:41
Yes..well, I figured you may end up there. We had the luxury of controlling our own xml format. I think there may be many xml standards, and Baan uses only 1, your output may use another. Yes, you have the possiblity to parse it first and put in your tags, but heck, if you are parsing the darn thing you may as well process it that way.
That's where I leave off. Maybe someone else with broader xml knowledge can tell if there is different standards, and if there is an easy way to switch between them. Maybe even playing with the DOCTYPE! stuff....? I am not sure if Baan really recognizes the dtd or what..