CreateDocumentElementNS - cXMLDOMDocument
Sets up the first/root element in a document (that is namespace aware)
Type: Function
Return Data Type: Handle
Parameters
| Parameter | Type | Description |
|---|---|---|
| sNamespace | String | |
| sTagName | String | The root element tag name |
Syntax
Function CreateDocumentElementNS String sNamespace String sTagName Returns Handle
Call Example
Get CreateDocumentElementNS sNamespace sTagName to HandleVariable
Description
CreateDocumentElementNS is used to set up the first element in a document. It should only be used when creating a new XML Document.
// 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
// build the rest of the document
:
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 CreateDocumentElementNS and not CreateDocumentElement ).
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
Handle 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) | AddElementNS(get) | CreateElementNodeNS | CreateAttributeNodeNS | AddAttributeNS
Return Value
If successful, the function returns an object handle for the newly created node. If zero is returned, the operation failed.