Try OpenEdge Now
skip to main content
Working with XML
Reading and Writing XML with the Document Object Model (DOM) : Namespaces
 

Namespaces

When you have nodes or attribute nodes that use namespaces, you need to supply the namespace information when you create the nodes. Therefore, there are different methods for creating nodes without namespaces and nodes with namespaces, as shown in the following table.
Table 2. X-document methods for creating nodes
Use this method for no namespaces
Use this method for namespaces
hX-document:CREATE-NODE( )
hX-document:CREATE-NODE-NAMESPACE( )
hX-noderef:SET-ATTRIBUTE( )
hX-noderef:SET-ATTRIBUTE-NODE( )
This is the syntax for the CREATE-NODE-NAMESPACE( ) method:

Syntax

CREATE-NODE-NAMESPACE(x-noderef-handle, namespace-URI, qualifiedName, type)
x-noderef-handle
A valid X-noderef handle to use for the new namespace aware DOM node.
namespace-URI
Represents the URI reference, which identifies the namespace. The namespace name should have the characteristics of uniqueness and persistence. It does not need to be directly usable for retrieval of a schema, but ordinary URLs can also be used to achieve this effect.
qualifiedName
The qualified name is the name of an element or attribute optionally prefixed by a valid namespace prefix and a colon character. Unless you are using a default namespace, a prefix is required and should be set to the prefix specified when you declared the namespace using the xmlns attribute.
type
A character expression that represents the node SUBTYPE, which will be either ELEMENT or ATTRIBUTE.
The following example creates an ELEMENT node with a namespace and an ATTRIBUTE node with a namespace on an X-document object:
errStat = hDocument:CREATE-NODE-NAMESPACE
  (hNsNode,
   "http://www.progress.com/NS/MyNamespace",
   "MyNS:MyNSElt",
   "element").

errStat = hDocument:CREATE-NODE-NAMESPACE
  (hAttributeWithNS,
   "http://www.progress.com/NS/MyNamespace",
   "MyNS:MyNSAttr",
   "attribute").
This is the syntax for the CREATE-NODE-NAMESPACE( ) method:

Syntax

SET-ATTRIBUTE-NODE (attr-node-handle)
attr-node-handle
A valid X-noderef handle created by CREATE-NODE-NAMESPACE( ) or CREATE-NODE( ).
The following example creates an ELEMENT node with a namespace and an ATTRIBUTE node with a namespace on an X-document object:
ABL:
ASSIGN
  hX-noderef-withNS:NAMESPACE-URI = "http://www.progress.com/NS/MyNamespace"
  hX-noderef-withNS:NAMESPACE-PREFIX = "MyNS"
  hX-noderef-withNS:NODE-VALUE = "Some attribute value"
  errStat = hNsNode:SET-ATTRIBUTE-NODE(hX-noderef-wNS).
XML:
<MyNS:MyNamespaceElement MyNS:MyNamespaceAttribute = "Some attribute value">
Note: Do not mix calls to the CREATE-NODE( ) method and the CREATE-NODE-NAMESPACE( ) method in the same DOM tree.