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
pbdom_element_name.AddNamespaceDeclaration(string strNamespacePrefix, string strNamespaceUri)
Argument |
Description |
---|---|
pbdom_element_name |
The name of a PBDOM_ELEMENT object |
strNamespacePrefix |
The prefix of the new namespace to be declared |
strNamespaceUri |
The URI of the new namespace to be declared |
Return value
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:
<Vehicle> <seats>4</seats> <color>Red</color> <engine> <capacity units="cc">1600</capacity> </engine> </Vehicle>
Given a PBDOM_ELEMENT object elem_vehicle that represents the Vehicle element, consider the following statement:
elem_vehicle.AddNamespaceDeclaration("vehicle_specs",& "http://www.vehicle.com/specs")
It transforms the Vehicle element as follows:
<Vehicle xmlns:vehicle_specs="http://www.vehicle.com/specs"> <seats>4</seats> <color>Red</color> <engine> <capacity units="cc">1600</capacity> </engine> </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:
elem_vehicle.AddNamespaceDeclaration("", & "http://www.vehicle.com/specs")
It transforms the Vehicle element as follows:
<Vehicle xmlns:"http://www.vehicle.com/specs"> <seats>4</seats> <color>Red</color> <engine> <capacity units="cc">1600</capacity> </engine> </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.
See also