AddElementNS - cXMLDOMDocument

Creates a new Element node (that is namespace aware) and appends it to the list

Type: Procedure

Parameters: String sNameSpace String sTagName String sValue

sNameSpaceThe element NamespaceURI
sTagNameThe name of the Element Tag
sValueValue of the element

Procedure AddElementNS String sNameSpace String sTagName String sValue

Call: Send AddElementNS sNameSpace sTagName sValue


AddElementNS creates a new node and appends it to the list. When used as a procedure, the object is destroyed. This procedure adds the node but does not return an object. Only elements usually have children (which is why there is also an AddElementNS function).

Send AddElementNS of hoRoot "" "Customer"  sCustName 
Send AddElementNS of hoRoot "" "Vendor"  sVndrName 

This sample creates two new node elements and appends them to hoRoot.

NamespaceURIs are always required. Usually the value will be represented as a string as follows:

Move "" to sNS
Send AddElementNS of hoRoot sNS "Customer"  sCustName 
Send AddElementNS of hoRoot sNS "Vendor"  sVndrName 

Note: If for any reason the node cannot be added to the document, an error will be generated.


This message creates a node and a document that is namespace aware. This requires that you always pass a NameSpaceURI. It is suggested that you always create documents using namespace methods (the methods that end in NS) and that you no longer use the non-namespace methods (e.g. use AddElementNS and not AddElement).

If your document does not have any namespaces or an element within the document does not have a namespace, its namespace is considered to be global and its NamespaceURI is represented as an empty string (""). In such a case you can and should use these namespace aware messages passing an empty string for the NameSpaceURI.


Function CustomerXMLList Returns XmlHandle
   Integer bOk
   Handle hoXML hoRoot hoEle hoXML1 hoRoot1
   Handle hoCustomerDD
   String sName sNumber sState sNamespace

   Move Customer_dd to hoCustomerDD

   // namespace to use for document
   Move "" to sNameSpace

   // create XML document / Create root node
   Get Create U_cXMLDomDocument To hoXML
   // Create the Root element named CustomerList
   Get CreateDocumentElementNS Of hoXML sNameSpace "CustomerList" To hoRoot
   // now go through all customer records
   Send Clear of hoCustomerDD
   Send Find of hoCustomerDD ge 2
   While (found)
       // get name, number and state to strings
       Move (trim(Customer.Name))    To sName
       Move Customer.Customer_Number To sNumber
       Move (trim(Customer.State))   To sState
       // for each customer create customer node with child elements
       Get AddElementNS Of hoRoot sNameSpace "Customer" "" To hoEle
          Send AddElementNS Of hoEle sNameSpace "Name"   sName
          Send AddElementNS Of hoEle sNameSpace "Number" sNumber
          Send AddElementNS Of hoEle sNameSpace "State"  sState
       Send Destroy of hoEle
       Send Find of hoCustomerDD gt 2
   Function_Return hoXML

See Also

AddElementNS(get) | CreateElementNodeNS | CreateAttributeNodeNS | AddAttributeNS | CreateDocumentElementNS