PBDOM_BUILDER:
BuildFromFile method
Description
Builds
a PBDOM_DOCUMENT from the file pointed to by the input
URL string. The URL can be a local file path.
Syntax
1 |
<span>pbdom_builder_name</span>.BuildFromFile (string<span> strURL</span>) |
Argument |
Description |
---|---|
pbdom_builder_name |
The name of a PBDOM_BUILDER |
strURL |
A string that indicates the URL of the |
Return Values
PBDOM_DOCUMENT.
Throws
EXCEPTION_MEMORY_ALLOCATION_FAILURE – If
there is insufficient memory to create a PBDOM_DOCUMENT
object.
Examples
Suppose the file c:pbdom_doc_1.xml contains
the following XML string:
1 |
<!DOCTYPE abc [<!ENTITY text "Some Text" >]><br><abc><br>  <data><br>    <child_data>Child Data Text</child_data><br>    <child_data An_Attribute="Some Attribute Value"/><br>    &text;<br>    <!--Comment String--><br>    <![CDATA[Some CDATA String]]><br>  </data><br></abc> |
The file contains a Document Type Declaration that indicates
that <abc> is the root element, and a declaration
for the text entity that expands to “Some Text”:The root element abc contains
a child element data, which contains five child PBDOM_OBJECTs:
two PBDOM_ELEMENT objects, and PBDOM_TEXT, PBDOM_COMMENT,
and PBDOM_CDATA objects.
The first child_data element
contains a PBDOM_TEXT with the string “Child Data
Text”. The second child_data element
contains no child PBDOM_OBJECTs but it does contain a PBDOM_ATTRIBUTE, An_Attribute,
that contains the value “Some Attribute Value”.
This example creates a PBDOM_DOCUMENT called pbdom_doc from c:pbdom_doc_1.xml,
tests the content of pbdom_doc, then
saves the DOM tree contained within pbdom_doc into
a separate file, c:pbdom_doc_2.xml.
The input and output files should be identical.
1 |
PBDOM_Builder     pbdom_bldr<br>PBDOM_Document    pbdom_doc<br>PBDOM_Object      pbdom_obj_array[]<br>PBDOM_Element     pbdom_elem<br>integer iFileNum1<br>long l = 0<br> <br>// Create a PBDOM_DOCUMENT from the XML file<br>  pbdom_bldr = Create PBDOM_Builder<br>  pbdom_doc = pbdom_bldr.BuildFromFile &<br>     ("c:pbdom_doc_1.xml")<br> <br>// Test the contents of the PBDOM_DOCUMENT<br>// First test the PBDOM_DOCTYPE in the document<br>  MessageBox ("PBDOM_DOCTYPE GetName()", &<br>     pbdom_doc.GetDocType().GetName())<br>  MessageBox ("PBDOM_DOCTYPE GetInternalSubset()", &<br>     pbdom_doc.GetDocType().GetInternalSubset())<br> <br>// Test the root element<br>  MessageBox ("PBDOM_DOC Root Element Name", &<br>     pbdom_doc.GetRootElement().GetName())<br> <br>// test the root element's child element<br>  MessageBox ("PBDOM_DOC <data> Element Name", &<br>     pbdom_doc.GetRootElement().GetChildElement &<br>     ("data").GetName())<br> <br>// Collect all the child PBDOM_OBJECTs of the<br>// <data> element<br>  pbdom_doc.GetRootElement().GetChildElement &<br>     ("data").GetContent(pbdom_obj_array)<br> <br>// Display the class name, the name and the text contained<br>// within each PBDOM_OBJECT array item <br>  for l = 1 to UpperBound(pbdom_obj_array)<br>    MessageBox ("Child Object " + string(l) + " Class",&<br>      pbdom_obj_array[l].GetObjectClassString())<br>    MessageBox ("Child Object " + string(l) + " Name",&<br>      pbdom_obj_array[l].GetName())<br>    MessageBox ("Child Object " + string(l) + " Text",&<br>      pbdom_obj_array[l].GetText())<br>  next<br> <br>// Retrieve and display the name and text value of the<br>// "An_Attribute" attribute from the <child_data> element <br>   pbdom_elem = pbdom_obj_array[2]<br>  MessageBox ("child_data Attribute name", &<br>    pbdom_elem.GetAttribute("An_Attribute").GetName())<br>  MessageBox ("child_data Attribute value", &<br>    pbdom_elem.GetAttribute("An_Attribute").GetText())<br> <br>// save the DOM Tree contained within pbdom_doc into<br>// a separate file "c:pbdom_doc_2.xml"<br>  pbdom_doc.SaveDocument ("c:pbdom_doc_2.xml")<br> <br>  Destroy pbdom_bldr<br> <br>CATCH (PBDOM_Exception except)<br>  MessageBox ("Exception Occurred", except.Text)<br>END TRY |
Usage
The input URL string can be a local file path.
The encoding specified in the XML export template determines
the encoding of the document created using BuildFromFile.