Will@Tait
20th April 2005, 03:25
Having searched BaanBoard fruitlessly for tips on how to use Baan's XML functions, I have figured out the following and thought I'd share it with everyone here for future reference.

Example code:


function main()
{
long orderid,linesid,lineid
long ret
long fh
domain tcmcs.str80 text
domain tcmcs.str80 error.msg

|* write

orderid = xmlNewNode("order",XML_ELEMENT)
linesid = xmlNewNode("lines",XML_ELEMENT, orderid)

lineid = xmlNewNode("line",XML_ELEMENT)
ret = xmlSetAttribute(lineid,"pos","123")
ret = xmlNewNode("text to output",XML_DATA,lineid)
|ret = xmlSetData(ret,"text value") |* needs a XML_DATA node to work - a bit pointless really, might as well use xmlNewNode(..., XML_DATA)
ret = xmlAppendToChilds(linesid,lineid)

lineid = xmlNewNode("line",XML_ELEMENT, linesid)
ret = xmlSetAttribute(lineid,"pos","456")
ret = xmlNewNode("text2",XML_DATA,lineid)
fh = seq.open("test.xml","w")
|ret=xmlWritePretty(fh,orderid,0)
ret=xmlWrite(fh,orderid,0)
seq.close(fh)
ret = xmlDelete(orderid)

|* read

fh = seq.open("test.xml","r")
orderid=xmlRead(fh,error.msg)
seq.close(fh)
|lineid=xmlFindFirstMatch("<order>.<lines>.<line pos=""123"">",orderid)
|lineid=xmlFindFirstMatch("<order>.<lines>.<line>",orderid)
linesid=xmlFindFirst("lines",orderid)
lineid=xmlGetFirstChild(linesid)
while lineid>0
ret=xmlGetAttribute(lineid,"pos",text)
message(text)
ret=xmlGetData(lineid,text)
message(text)
lineid=xmlGetRightSibling(lineid)
endwhile
ret = xmlDelete(orderid)

}


The above script creates the following XML:

<?xml version="1.0"?><order><lines><line pos="123">text to output</line><line pos="456">text2</line></lines></order>

Hope you find it useful!

Will@Tait
20th April 2005, 03:43
I do another seach on BaanBoard and find heaps. Grrrr!

The best info I've found so far is in:
http://http//secure1.support.baan.com/ftpdownload/updates/B40c4/progguide.chm

You'll need access to the Baan Support FTP Site.

günther
8th May 2007, 11:03
Hi Will,

thanks a lot for your complete example. I've just been able to create my first xml writer and reader with these functions.

Günther

mr_suleyman
8th May 2007, 11:07
I think that it doesn't support complex XML structure. It is limitied for XML operations. But it's well to see on baan like tool.

Mr_Suleyman

Junior
9th May 2007, 05:56
~gunther - You're welcome (tis Will@Tait here - I just lost access to my old a/c and created a new one)

~mr_suleyman - Do you have any specific examples that Baan fails to handle? I've since used the XML alot and found it to be very powerful/useful, but as I tend to use the same few functions over and over, I am possibly not seeing what you are...?

mr_suleyman
9th May 2007, 08:07
I also dealed with a lot. I have some xml files that the tools couldn't parse it properly. If the file size is small , it's ok but for large file it failed. These xml files are secret data for us. I couldn't sent them. But I see the problems on board like mine.

rajram_123
6th May 2008, 13:19
Hi

Can anyone tell me what is the difference between XML functions - xmlduplicateandAdd(), xmlduplicateandAppend() and xmlduplicateandappendtochilds(), xmlduplicateandinsertinchilds().

Thx

Rama

baangeek77
19th July 2011, 15:50
Thanks so much for the code, it really helped a lot!!