Sorry for draft quality, I have to improve my English !
Good practice
Always separate the setup and filling process.
Ideally move all your filling functions on service program. The reason why ? maximizing their use. Value is what is in the box, not the box itself !
Put ifsxml_setRootName() and ifsxml_close() on the same function.
…and calls all filling functions between.
Finally, one flow = three procedures.
Split the logic on three levels : Resource / Document / Data :
- Resource function – ifsxml_new(), ifsxml_createFile() etc.
- Document function – ifsxml_setRootName()
- Data function – ifsxml_addElement(), _closeElement() etc.
- Document function – ifsxml_setRootName()
Pass the Handle to all procedures, don’t use global variable.
…and don’t test the validity of the Handle at the level of document or filling function . It is the responsibility of the creator of the handle. You must assume that the function is called precisely because this handle is valid !
p filling_function...
p b
d pi
d hXml_...
d value like(m_ifsxml_handle)
/free
ifsxml_openElement(hXml_: 'element');
ifsxml_addElement(hXml_: 'element': 'value');
ifsxml_closeElement(hXml_);
/end-free
p e
Tips
Create one function for each complex data structures that you want « xmlize »
d m_ds_contact...
d ds qualified based(null)
d
d firstname...
d 64a varying
d name...
d 64a varying
d email...
d 256a varying
Function to export m_ds_contact above.
p xmlexp_ds_contact..
p b
d pi
d hXml_...
d value like(m_ifsxml_handle)
d p_ds_contact_...
d * value
d contact_...
d ds likeds(m_ds_contact) based(p_ds_contact_)
/free
xmlifs_openElement(hXml_: 'contact');
xmlifs_addElement(hXml_: 'firstname': contact_.firstname);
xmlifs_addElement(hXml_: 'name': contact_.name);
xmlifs_addElement(hXml_: 'email': contact_.email);
xmlifs_closeElement(hXml_);
/end-free
Adding Namespaces
You can add Namespaces declarations with ifsxml_addAttributes() after ifsxml_setRootName() and simply create prefixed element with the name space as bellow :
.../...
ifsxml_setRootName(hXml: 'xsl:stylesheet');
ifsxml_addAttribute(hXml: 'version': '1.0');
ifsxml_addAttribute(hXml: 'xmlns:xsl': 'http://www.w3.org/1999/XSL/Transform');
// <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
.../...
ifsxml_openElement(hXml: 'xsl:template');
ifsxml_addAttribute(hXml: 'match': '/');
// <xsl:template match="/">
.../...
Misc
Multithreading
I dis not run test on multithread environment, but, theoretically, for that work you must add « serialize » (from v6r1 only) on ifsxml_init() or call it before any thread. Of course, don’t use a same handle on different threads.