PBDOM_ELEMENT:
AddNamespaceDeclaration method
Description
Adds
a new namespace declaration to this PBDOM_ELEMENT object.
The new namespace can apply to the PBDOM_ELEMENT object
itself if the namespace becomes the default namespace in the PBDOM_ELEMENT object.
Syntax
1 |
<span>pbdom_element_name</span>.AddNamespaceDeclaration(string <span>strNamespacePrefix</span>, string <span>strNamespaceUri</span>) |
Argument |
Description |
---|---|
pbdom_element_name |
The name of a PBDOM_ELEMENT |
strNamespacePrefix |
The prefix of the new namespace to be |
strNamespaceUri |
The URI of the new namespace to be declared |
Return Values
PBDOM_ELEMENT. The modified PBDOM_ELEMENT
object.
Throws
EXCEPTION_INVALID_ARGUMENT – If
any of the input parameters is invalid (null).
EXCEPTION_INVALID_NAME – If
the input Prefix is invalid, as, for example, if it contains a colon.
EXCEPTION_INVALID_STRING – If
the input URI is invalid.
EXCEPTION_MEMORY_ALLOCATION_FAILURE – If
memory allocation failure occurred in this method.
Examples
Consider the following element:
1 |
<Vehicle><br>  <seats>4</seats><br>  <color>Red</color><br>  <engine><br>     <capacity units="cc">1600</capacity><br>  </engine><br></Vehicle> |
Given a PBDOM_ELEMENT object elem_vehicle that
represents the Vehicle element, consider the
following statement:
1 |
elem_vehicle.AddNamespaceDeclaration("vehicle_specs",&<br>   "http://www.vehicle.com/specs") |
It transforms the Vehicle element as
follows:
1 |
<Vehicle xmlns:vehicle_specs="http://www.vehicle.com/specs"><br>  <seats>4</seats><br>  <color>Red</color><br>  <engine><br>     <capacity units="cc">1600</capacity><br>  </engine><br></Vehicle> |
Vehicle, seats, color, engine,
and capacity are all unqualified (that is,
they have no namespace prefix). Therefore, the vehicle_specs namespace
does not apply to any of them or their attributes or subelements.
However, consider the following statement:
1 |
elem_vehicle.AddNamespaceDeclaration("", &<br>   "http://www.vehicle.com/specs") |
It transforms the Vehicle element as
follows:
1 |
<Vehicle xmlns:"http://www.vehicle.com/specs"><br>  <seats>4</seats><br>  <color>Red</color><br>  <engine><br>     <capacity units="cc">1600</capacity><br>  </engine><br></Vehicle> |
http://www.vehicle.com/specs is
the default namespace and so Vehicle, seats, color, engine,
and capacity are all part of this namespace.
Note that the default namespace does not apply
to the units attribute.