baanware
21st October 2004, 11:54
Hi All,
I am trying to read an XML file, but cannot make my program identify the contents of the xml-element. I have made the script below to create a simple xml-file describing my problem. The resulting file looks as follows:
<?xml version="1.0"?>
<Supplier>
<SupplierID>123456</SupplierID>
<Name>Customer Named XXX</Name>
<Address>Address YYY</Address>
</Supplier>
The file was generated by the following sample function:
function create.xml.document( domain tcsuno i.suno,
domain tcnama i.nama,
domain tcnamc i.namc)
{
BaanDocId = xmlNewNode("Supplier") |* , XML_ELEMENT, dtdId)
retVal = xmlNewDataElement("SupplierID", strip$(shiftl$(i.suno)), BaanDocId)
retVal = xmlNewDataElement("Name", strip$(shiftl$(i.nama)), BaanDocId)
retVal = xmlNewDataElement("Address", strip$(shiftl$(i.namc)), BaanDocId)
fd = seq.open("file.xml", "w" )
retVal = xmlWritePretty(fd, BaanDocId, 0 )
retVal = seq.close(fd)
retVal = xmlDelete(BaanDocId, 0)
}
Having written the file, I try to read it, and to determine the contents of the <Name> element.
function read.xml.document()
{
long fileid
long suppliernode
string error_string(120)
string xml.data(50)
|open the xml file for reading.
fd = seq.open ("file.xml", "r" )
|parse the xml file
fileid = xmlread(fd, error_string)
seq.close(fd)
|determine the data-elements
suppliernode = xmlfindmatch("<Supplier>", fileid)
if (suppliernode <> 0 ) then
retval = xmlgetdataelement(suppliernode, "<Name>", xml.data)
retval = xmlgetdataelement(suppliernode, "Name", xml.data)
retval = xmlgetdataelement(suppliernode, "", xml.data)
endif
retval = xmldelete(fileid, 0)
}
As you can see I have tried several ways to isolate the content of the "Name" element , but none of them results in the expected value
of the result-string xml.data ( = "Customer Named XXX").
Can anyone tell me how to do?
Thanks!
I am trying to read an XML file, but cannot make my program identify the contents of the xml-element. I have made the script below to create a simple xml-file describing my problem. The resulting file looks as follows:
<?xml version="1.0"?>
<Supplier>
<SupplierID>123456</SupplierID>
<Name>Customer Named XXX</Name>
<Address>Address YYY</Address>
</Supplier>
The file was generated by the following sample function:
function create.xml.document( domain tcsuno i.suno,
domain tcnama i.nama,
domain tcnamc i.namc)
{
BaanDocId = xmlNewNode("Supplier") |* , XML_ELEMENT, dtdId)
retVal = xmlNewDataElement("SupplierID", strip$(shiftl$(i.suno)), BaanDocId)
retVal = xmlNewDataElement("Name", strip$(shiftl$(i.nama)), BaanDocId)
retVal = xmlNewDataElement("Address", strip$(shiftl$(i.namc)), BaanDocId)
fd = seq.open("file.xml", "w" )
retVal = xmlWritePretty(fd, BaanDocId, 0 )
retVal = seq.close(fd)
retVal = xmlDelete(BaanDocId, 0)
}
Having written the file, I try to read it, and to determine the contents of the <Name> element.
function read.xml.document()
{
long fileid
long suppliernode
string error_string(120)
string xml.data(50)
|open the xml file for reading.
fd = seq.open ("file.xml", "r" )
|parse the xml file
fileid = xmlread(fd, error_string)
seq.close(fd)
|determine the data-elements
suppliernode = xmlfindmatch("<Supplier>", fileid)
if (suppliernode <> 0 ) then
retval = xmlgetdataelement(suppliernode, "<Name>", xml.data)
retval = xmlgetdataelement(suppliernode, "Name", xml.data)
retval = xmlgetdataelement(suppliernode, "", xml.data)
endif
retval = xmldelete(fileid, 0)
}
As you can see I have tried several ways to isolate the content of the "Name" element , but none of them results in the expected value
of the result-string xml.data ( = "Customer Named XXX").
Can anyone tell me how to do?
Thanks!