XML_TEXT
Argument | Enumeration | Purpose |
---|---|---|
handle | Handle | |
SYM(rowbuf$) | Symbol of row buffer | |
SYM(text$) | Symbol of result text buffer | |
mode | Mode: RAW, XMLData etc. | |
SYM(col()) | Optional column array | |
status | KDB_ERROR_ENUM | Return status |
len | Length of result buffer |
XML_TEXT
Given a row buffer and the handle it was read from, this function can be used to convert the row to XML describing the data. If the symbol of the return buffer is negative then, if necessary, the buffer will be re-dimensioned large enough to accommodate the requested information. This allows the use of XML as a transport for arbitrary database information.
The fifth argument can be zero, indicating that all the columns should appear in the buffer. Optionally it can be the SYM() of a numeric array of columns numbers. In this case only the columns listed, in the order they are listed, will appear. A column number of zero indicates the end of the list.
Mode | XML data format |
---|---|
1 | RAW |
2 | XMLData |
3 | EXPLICIT |
To output a few rows from a table as XML:
: DIM xsl$1024,rowbuf$1024,buffer$(1)1,magic$4 : DIM ki_status,ki_connect,ki_handle,mode,len,i,cols(10) : CALL KI_ALLOC_CONNECT 0 TO ki_connect,ki_status : IF (ki_status<>0) THEN 'error("ALLOC_CONNECT") : CALL KI_CONNECT "KDB",ki_connect,"WEB"," "," " TO ki_status : IF (ki_status<>0) THEN 'error("CONNECT") : CALL KI_ALLOC_HANDLE 0,ki_connect TO ki_handle,ki_status : IF (ki_status<>0) THEN 'error("ALLOC_HANDLE") : CALL KI_OPEN ki_handle,"userlist","R" TO ki_status : IF (ki_status<>0) THEN 'error("OPEN") : magic$ = BIN(4101,4) : CALL KI_START ki_handle,magic$,1 TO ki_status : IF (ki_status<>0) THEN 'error("START") : xsl$ = "/testdir/test.xml" : cols(1) = 1 : cols(2) = 2 : cols(3) = 3 : cols(4) = 0 : mode = 2 : PRINT "<?xml version=""1.0"" ?>" : PRINT "<?xml-stylesheet type=""text/xsl"" href=""";xsl$;""" ?>" : PRINT "<root>" : FOR i = 1 TO 3 : CALL KI_READ_NEXT ki_handle,1,SYM(rowbuf$) TO ki_status : IF (ki_status<>0) THEN 'error("READ NEXT") : CALL XML_TEXT ki_handle,SYM(rowbuf$),-SYM(buffer$()),mode,SYM(cols()) TO ki_status, len : IF (ki_status<>0) THEN 'error("XML_TEXT") : PRINT STR(buffer$(),,len) : NEXT i : PRINT "</root>" : CALL KI_CLOSE ki_handle TO ki_status : IF (ki_status<>0) THEN 'error("CLOSE") : ENDCould produce the following output. Note that an alternative could be to use the KI_SQL command.
<?xml version="1.0" ?> <?xml-stylesheet type="text/xsl" href="/testdir/test.xsl" ?> <root> <USERLIST MAGIC="4101" COMMAGIC="0" CREATED="2000-07-23" /> <USERLIST MAGIC="4102" COMMAGIC="67.76" CREATED="2000-07-23" /> <USERLIST MAGIC="4103" COMMAGIC="44" CREATED="2000-07-24" /> </root>