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!
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!