PBDOM_CHARACTERDATA:
GetObjectClassString method
Description
The GetObjectClassString method
returns a string form of the class of the PBDOM_OBJECT.
Syntax
|
1 |
<span>pbdom_object_name</span>.GetObjectClassString(<span></span>) |
|
Argument |
Description |
|---|---|
|
pbdom_object_name |
The name of a PBDOM_OBJECT |
Return Values
String. GetObjectClassString returns
a string that indicates the class of the current PBDOM_OBJECT.
The possible return values for classes inherited from PBDOM_CHARACTERDATA
are:
-
pbdom_text
-
pbdom_cdata
-
pbdom_comment
The PBDOM_CHARACTERDATA class itself cannot be instantiated,
so the string “pbdom_characterdata” is
never returned.
Examples
This example creates a PBDOM_DOCUMENT based
on the following DOM tree:
|
1 |
<abc><br>   <data><br>      Data with a &lt; character<br>      <!-- Comment with a &lt; character --><br>      <![CDATA[ CDATA with an actual > character and <br>        an entity reference &lt; ]]><br>   </data><br></abc> |
The PowerScript code obtains the root element, uses it to
obtain the child element, and then obtains an array of the child
element’s own children. This is an array of three PBDOM_OBJECTs,
each of which is a child node of data. This
array provides the ability to access and manipulate the child nodes,
but to illustrate the virtual nature of the PBDOM_CHARACTERDATA
class and the calling of methods of the PBDOM_CHARACTERDATA
class, the example defines an array of PBDOM_CHARACTERDATA
objects.
Each array item of the pbdom_obj_array is
assigned to the pbdom_chardata array,
so you can call the methods of each array item without needing to
know what subclass the item belongs to.
Children must be subclasses of PBDOM_CHARACTERDATA
If the data element contained a child
that was not a subclass of PBDOM_CHARACTERDATA, the FOR loop
to assign each pbdom_obj_array item
to a corresponding pbdom_chardata array
item would fail when it reached that item.
The MessageBox calls illustrate how the entity reference < is
handled by the different PBDOM_CHARACTERDATA subclasses.
In the PBDOM_TEXT object, it is expanded. In the PBDOM_COMMENT
and PBDOM_CDATA objects, it is not. The character to which
the entity reference refers, “>”, can
also be included in a PBDOM_CDATA object.
|
1 |
PBDOM_Builder         pbdombuilder_new<br>pbdom_document        pbdom_doc<br>pbdom_element         pbdom_elem<br>PBDOM_CHARACTERDATA   pbdom_chardata[]<br>PBDOM_OBJECT          pbdom_obj_array[]<br>long l = 0<br>string strXML = "<abc><data>Data with a &lt; character<!-- Comment with a &lt; character --><![CDATA[ CDATA with an actual > character and an entity reference &lt; ]]></data></abc>"<br> <br>TRY<br>   pbdombuilder_new = Create PBDOM_Builder<br>   pbdom_doc = pbdombuilder_new.BuildFromString (strXML)<br> <br>   pbdom_elem = pbdom_doc.GetRootElement(). &<br>      GetChildElement("data")<br>   pbdom_elem.GetContent(pbdom_obj_array)<br> <br>// populate an array of PBDOM_CHARACTERDATA objects<br>   for l = 1 to UpperBound(pbdom_obj_array)<br>      pbdom_chardata[l] = pbdom_obj_array[l]<br>   next <br>   for l = 1 to UpperBound(pbdom_chardata)<br>     MessageBox ("Class", &<br>        pbdom_chardata[l].GetObjectClassString())<br>     MessageBox ("Text", pbdom_chardata[l].GetText())<br>   next <br> <br>   Destroy pbdombuilder_new<br> <br>CATCH (PBDOM_Exception except)<br>   MessageBox ("Exception Occurred", except.Text)<br>END TRY |