GetObjectClassString

Description

The GetObjectClassString method returns a string form of the class of the PBDOM_OBJECT.

Syntax

pbdom_object_name.GetObjectClassString()

Argument

Description

pbdom_object_name

The name of a PBDOM_OBJECT


Return value

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:

<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>

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 &lt; 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.

PBDOM_Builder         pbdombuilder_new
pbdom_document        pbdom_doc
pbdom_element         pbdom_elem
PBDOM_CHARACTERDATA   pbdom_chardata[]
PBDOM_OBJECT          pbdom_obj_array[]
long l = 0
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>"

TRY
   pbdombuilder_new = Create PBDOM_Builder
   pbdom_doc = pbdombuilder_new.BuildFromString (strXML)

   pbdom_elem = pbdom_doc.GetRootElement(). &
      GetChildElement("data")
   pbdom_elem.GetContent(pbdom_obj_array)

// populate an array of PBDOM_CHARACTERDATA  objects
   for l = 1 to UpperBound(pbdom_obj_array)
      pbdom_chardata[l] = pbdom_obj_array[l]
   next 
   for l = 1 to UpperBound(pbdom_chardata)
     MessageBox ("Class", &
        pbdom_chardata[l].GetObjectClassString())
     MessageBox ("Text", pbdom_chardata[l].GetText())
   next 

   Destroy pbdombuilder_new

CATCH (PBDOM_Exception except)
   MessageBox ("Exception Occurred", except.Text)
END TRY

See also

GetObjectClass