PBDOM_ATTRIBUTE
The PBDOM_ATTRIBUTE class represents an XML attribute
modeled in PowerScript. The PBDOM_ATTRIBUTE methods allow
access to element attributes and namespace information.
Methods
In addition to the methods inherited from PBDOM_OBJECT,
the PBDOM_ATTRIBUTE class has the following methods:
-
GetBooleanValue, SetBooleanValue, GetDateValue, SetDateValue, GetDateTimeValue, SetDateTimeValue, GetDoubleValue, SetDoubleValue, GetIntValue, SetIntValue, GetLongValue, SetLongValue, GetRealValue, SetRealValue, GetTimeValue, SetTimeValue, GetUIntValue, SetUintValue, GetULongValue,and SetULongValue to
get and set the value of the PBDOM_ATTRIBUTE as the specified
datatype -
GetNamespacePrefix and GetNamespaceURI to
get the prefix and URI of the namespace associated with the PBDOM_ATTRIBUTE -
GetOwnerElementObject and
SetOwnerElementObject to get and set the owner PBDOM_ELEMENT
of the PBDOM_ATTRIBUTE -
GetQualifiedName to
get the full name of the PBDOM_ATTRIBUTE including the
prefix, if any -
SetNamespace to
set the namespace of the PBDOM_ATTRIBUTE -
SetText to
set the text content of the PBDOM_ATTRIBUTE
Child PBDOM_OBJECTs
A PBDOM_ATTRIBUTE contains a subtree of child PBDOM_OBJECTs.
The child objects can be a combination of PBDOM_TEXT and PBDOM_ENTITYREFERENCE
objects.
The following example produces a PBDOM_ELEMENT named elem that contains
a PBDOM_ATTRIBUTE named attr:
1 |
PBDOM_ATTRIBUTE pbdom_attr<br>PBDOM_TEXT pbdom_txt<br>PBDOM_ENTITYREFERENCE pbdom_er<br>PBDOM_ELEMENT pbdom_elem<br> <br>pbdom_elem = Create PBDOM_ELEMENT <br>pbdom_elem.SetName ("elem")<br> <br>pbdom_attr = Create PBDOM_ATTRIBUTE<br>pbdom_attr.SetName("attr")<br>pbdom_attr.SetText("Part 1 ")<br> <br>pbdom_txt = Create PBDOM_TEXT<br>pbdom_txt.SetText (" End.")<br> <br>pbdom_er = Create PBDOM_ENTITYREFERENCE <br>pbdom_er.SetName("ER")<br> <br>pbdom_attr.AddContent(pbdom_er)<br>pbdom_attr.AddContent(pbdom_txt)<br> <br>pbdom_elem.SetAttribute(pbdom_attr) |
The element tag in the XML looks like this:
1 |
<elem attr="Part 1 &ER; End."> |
In Figure 14-3,
the arrows indicate a parent-child relationship between the PBDOM_ATTRIBUTE
and the other PBDOM_OBJECTs:
Figure 14-3: PBDOM_ATTRIBUTE
subtree example
The Default PBDOM_TEXT child
A PBDOM_ATTRIBUTE generally always contains at least
one PBDOM_TEXT child that might contain an empty string.
This is the case unless the RemoveContent method
has been called to remove all contents of the PBDOM_ATTRIBUTE.
The following examples show how a PBDOM_TEXT object
with an empty string can become the child of a PBDOM_ATTRIBUTE.
Example 1
The following example uses the PBDOM_ELEMENT SetAttribute method.
The name of the PBDOM_ATTRIBUTE is set to attr but the
text value is an empty string. The PBDOM_ATTRIBUTE will
have one child PBDOM_TEXT that will contain an empty string:
1 |
PBDOM_DOCUMENT  pbdom_doc<br>PBDOM_ATTRIBUTE  pbdom_attr<br>PBDOM_OBJECT    pbdom_obj_array[]<br> <br>try<br> <br>  pbdom_doc = Create PBDOM_DOCUMENT<br>  pbdom_doc.NewDocument("root")<br> <br>  // Note that the name of the attribute is set to<br>  // "attr" and its text value is the empty string ""<br>  pbdom_doc.GetRootElement().SetAttribute("attr", "")<br>  <br>  pbdom_attr = &<br>     pbdom_doc.GetRootElement().GetAttribute("attr")<br> <br>  MessageBox ("HasChildren", &<br>     string(pbdom_attr.HasChildren()))<br>  <br>catch(PBDOM_EXCEPTION pbdom_except)<br>  MessageBox ("PBDOM_EXCEPTION", &<br>     pbdom_except.GetMessage())<br>end try |
When you use the SaveDocument method to
render pbdom_doc as XML, it looks
like this:
1 |
<root attr="" /> |
Example 2
The following example creates a PBDOM_ATTRIBUTE and
sets its name to attr. No text value is set,
but a PBDOM_TEXT object is automatically created and attached
to the PBDOM_ATTRIBUTE. This is the default behavior for
every PBDOM_ATTRIBUTE created in this way:
1 |
PBDOM_DOCUMENT  pbdom_doc<br>PBDOM_ATTRIBUTE  pbdom_attr<br> <br>try<br>  pbdom_doc = Create PBDOM_DOCUMENT<br>  pbdom_doc.NewDocument("root")<br>  <br>  // Create a PBDOM_ATTRIBUTE and set its name to "attr"<br>  pbdom_attr = Create PBDOM_ATTRIBUTE<br>  pbdom_attr.SetName("attr")<br> <br>  pbdom_doc.GetRootElement().SetAttribute(pbdom_attr)<br>  <br>  MessageBox ("HasChildren", &<br>     string(pbdom_attr.HasChildren()))<br>  <br>catch(PBDOM_EXCEPTION pbdom_except)<br>  MessageBox ("PBDOM_EXCEPTION", &<br>     pbdom_except.GetMessage())<br>end try |
When you call the SetText method (or any
of the other Set* methods except SetNamespace),
the default PBDOM_TEXT is replaced by a new PBDOM_TEXT.
If you call the SetContent method, you can replace
the default PBDOM_TEXT by a combination of PBDOM_TEXT
and PBDOM_ENTITYREFERENCE objects.