The Document Object Modeling (DOM) classes / The DomDocument class |
The HTML language provides tags that allow the user to provide an embedded style sheet (the "style" tag) and to write embedded client side script (the "script" tag). According to the HTML 4.0 specification, the content of these tags must be managed as CDATA section.
IMPORT XML MAIN DEFINE myDoc XML.DomDocument DEFINE myEltNode, myAttrNode, bodyNode, myCdataNode XML.DomNode DEFINE nodeLst XML.DomNodeList DEFINE i INTEGER TRY LET myDoc = XML.DomDocument.create() CALL myDoc.setFeature("enable-html-compliancy", 1) CALL myDoc.load("testHtml.html") LET myEltNode = myDoc.CreateElement("script") LET myCdataNode = myDoc.CreateCDATASection("document.write(\"CDATA\");") LET myAttrNode = myDoc.CreateAttribute("type") CALL myAttrNode.setNodeValue("text/javascript") LET nodeLst = myDoc.getElementsByTagName("body") LET docNode = nodeLst.getItem(1) CALL docNode.appendChild(myEltNode) CALL myEltNode.setAttributeNode(myAttrNode) CALL myEltNode.appendChild(myCdataNode) CATCH DISPLAY "ERROR : ", STATUS, " - ", SQLCA.SQLERRM EXIT PROGRAM(-1) END TRY END MAIN