AddElementNS - cXMLDOMDocumentFragment

Creates a new Element node (that is namespace aware), appends it to the list, and returns its object handle

Type: Function

Return Data Type: Handle

Parameters: string sNameSpace String sTagName String sValue

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


Return Value

Return the object handle of the newly created XML element object


Syntax
Function AddElementNS string sNameSpace String sTagName String sValue Returns Handle

Call: Get AddElementNS sNameSpace sTagName sValue to HandleVariable


Description

AddElementNS creates a new node and appends it to the list. This procedure adds the node and returns an object. This allows you to create additional child nodes for the element. If you element does not have child nodes (elements or attributes) you can use the procedure AddElementNS.

Get AddElementNS of hoRoot "http://www.dataaccess.com/Test/CustomerList" "Customer"  ""  to hoCust
Send AddAllCustomers hoCust
Send Destroy of hoCust

This sample creates a new node element and append it to hoRoot. It then calls a method to perform extra processing on the element node.

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

Move "http://www.dataaccess.com/Test/CustomerList" to sNS
:
Get AddElementNS of hoRoot sNS "Customer"  ""  to hoCust
Send AddAllCustomers hoCust
Send Destroy of hoCust

Namespaces

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.

Example

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

   Move Customer_dd to hoCustomerDD

   // namespace to use for document
   Move "http://www.dataaccess.com/Test/CustomerList" 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
   Loop
   Function_Return hoXML
End_Function

See Also

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