Node creation methods usage examples

Node creation methods usage examples for the xml.DomDocument class.

Creating a node for the DomDocument is done in two steps:

Each time you create a node, you need to append it at the right place in the DomDocument. To add a node the document use the DomDocument management methods or the DomNode manipulation methods.

createNode("<LastName>PATTERSON</LastName><FirstName>Andrew</FirstName>")
Creates a structure of nodes.
createElement("CardList")
Produces
<CardList>
createElementNS("cny", "Company", "http://www.mysite.com/")
Produces <cny:Company xmlns:cny="http://www.mysite.com/"/> or <cny:Company />. See Cautions for more details.
createAttribute("Country")
Creates a Country attribute node.
createAttributeNS("tw","Town","http://www.mysite.com/cities")
Produces xmlns:tw="http://www.mysite.com/cities" tw:Town=""
createTextNode("My Company")
Creates a text node.
createComment("End of the card")
Produces<!--End of the card-->
createCDATASection("<website><a href=\"www.mysite.com\">My 
Company</a></website>")
Produces<![CDATA[<website><a href="www.mysite.com">My Company</a></website>]]>
createEntityReference("title")
Creates the entity reference &title.
createProcessingInstruction("xml-stylesheet", "type=\"text/xsl\"
href=\"card.xsl\"")
Produces<?xml-stylesheet type="text/xsl"href="card.xsl"?>
createDocumentType("Card", NULL, NULL,"<!ELEMENT 
Card (lastname, firstname, company, location)>")
Produces <!DOCTYPE Card [ <!ELEMENT Card (lastname , firstname , company , location)>]>
createDocumentFragment
Is a method that creates a lightweight DomDocument. It represents a subtree of nodes that do not need to conform to well-formed XML rules. This makes DocumentFragment easier to manipulate than a DomDocument.
for i=1 to 5
  let node = doc.createelement("Card")
  call root.appendchild(node) end for
This produces a subtree with 5 Card nodes that do not have any root node. Once the subtree is completed, it can be added to the DomDocument object like any other node.