Submitted by Anonymous (not verified) on Fri, 05/08/2015 - 00:00
Forums

Hi,

How can I extract a XML node into a string, memory or ILOB?

Niels Liisberg

Fri, 05/08/2015 - 00:00

Hi,

The xml_asXmlText and xml_asXmlTextMem do exactly that:

Take a look at example QSAMPLE/QSRC/XMLPARS390

* ------------------------------------------------------------- *
H BndDir('XMLPARSER' : 'ICEBREAK') dftactgrp(*NO) ACTGRP('QILE' )
d pXml s *
d pElem s *
d p1 s *
d len s 10u 0
d msg s 50 varying
d s s 32766 varying
/include xmlparser
/include qasphdr,ilob
/free

pxml = xml_ParseFile('/samples/xml/XmlSample2.xml');

if xml_Error(pxml) ;
   msg = xml_Message(pxml);
   xml_dump(pxml);
   xml_Close(pxml);
   return;
endif;

// Handle the sixth element
pElem = xml_locate(pxml : '/Myroot/Myelement[5]');

// Strings
s = xml_AsXmlText (pElem);

// as memory - here ILOB, but any memory will do
p1 = ILOB_OpenPersistant('QTEMP':'P1': 4096:0);
len = xml_AsXmlTextMem ( pElem : p1);
ilob_setLength(p1 : len);

// Save to a stream
ilob_SaveToBinaryStream(p1:'/samples/xml/sixthElement.xml');

xml_Close(pxml);
*inlr = *on;

Best regards,

Niels LiisbergĀ