Skip to content

AddAttributeNS - cXMLDOMNode

Creates an attribute node (that is namespace aware) and adds it to the element node

Type: Procedure

Parameters

Parameter Type Description
sNameSpace String the attribute NamespaceURI
sName String the name of the attribute node, including a prefix.
sValue String the value of the attribute node

Syntax

Procedure AddAttributeNS String sNameSpace String sName String sValue

Call Example

Send AddAttributeNS sNameSpace sName sValue

Description

AddAttributeNS encapsulates creation and addition of attributes to an element node. This procedure creates the attribute, sets the values and adds it to the element node that received the message.

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

This sample adds an attribute using a namespace. Note the use of the prefix (m:).

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

Attributes are often added to the global namespace. This sample creates an attribute with a global ("") namespace.

// add attribute with no namespace or prefix 
Send AddAttributeNS Of  hoEle "" "table" iTable

You could also use the AddAttribute to create such an attribute

Send AddAttribute Of  hoEle "table" iTable

Attributes and Namespaces

This message creates a node and a document that is namespace aware. This requires that you always pass a NameSpaceURI. Attributes are less likely to use namespaces (i.e., they are more likely to use the global namespace).Attributes never use the default namespace (xmlns="xx"). If the attribute does not have a prefix, it is in the global namespace.If a namespace is used, a prefix must be supplied. A prefix is supplied by adding the prefix to the sName (e.g., sName="m:table"). 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.

See Also

AttributeValueNS | RemoveAttributeNS | CreateAttributeNodeNS | AddElementNS(send) | AddElementNS(get) | CreateDocumentElementNS | CreateElementNodeNS