Creating an XML document from XML
The PBDOM_BUILDER class provides three methods for
creating a PBDOM_DOCUMENT from an existing XML source.
It also provides the GetParseErrors method to get a list of any
parsing errors that occur.
Using BuildFromString
The following example uses an XML string and the PBDOM_BUILDER
class to create a PBDOM_DOCUMENT. First the objects are
declared:
1 |
PBDOM_BUILDER pbdom_builder_new<br>PBDOM_DOCUMENT pbdom_doc |
The objects are then instantiated using the constructor and
the PBDOM_BUILDER BuildFromString method:
1 |
pbdombuilder_new = Create PBDOM_Builder<br>pbdom_doc = pbdombuilder_new.BuildFromString(Xml_doc) |
XML can also be loaded directly into a string variable, as
in the following example:
1 |
string Xml_str<br>Xml_str = "<?xml version="1.0" ?>"<br>Xml_str += "<WHITEPAPER>"<br>Xml_str += "<TITLE>Document Title</TITLE>"<br>Xml_str += "<AUTHOR>Author Name</AUTHOR>"<br>Xml_str += "<PARAGRAPH>Document text.</PARAGRAPH>"<br>Xml_str += "</WHITEPAPER>" |
Using BuildFromFile
You can create an XML file using the BuildFromFile method
and a string containing the path to a file from which to create
a PBDOM_DOCUMENT:
1 |
PBDOM_BUILDER     pbdombuilder_new<br>PBDOM_DOCUMENT     pbdom_doc<br>pbdombuilder_new = Create PBDOM_Builder<br>pbdom_doc = pbdombuilder_new.BuildFromFile &<br>   ("c:pbdom_doc_1.xml") |
Using BuildFromDataStore
The following PowerScript code fragment demonstrates how to
use the BuildFromDataStore method with a referenced
DataStore object.
1 |
PBDOM_Builder pbdom_bldr<br>pbdom_document pbdom_doc<br>datastore ds<br> <br>ds = Create datastore<br>ds.DataObject = "d_customer"<br>ds.SetTransObject (SQLCA)<br>ds.Retrievepbdom_doc = pbdom_bldr.BuildFromDataStore(ds) |
Using GetParseErrors
After a call to any of the Build methods, you can obtain a
list of parsing and validating errors encountered by the Build methods
with the GetParseErrors method:
1 |
PBDOM_Builder pbdom_bldr<br>pbdom_document pbdom_doc<br>string strParseErrors[]<br>BOOLEAN bRetTemp = FALSE<br> <br>pbdom_buildr = Create PBDOM_BUILDER<br>pbdom_doc = pbdom_buildr.BuildFromFile("D: emp.xml")<br>bRetTemp = pbdom_buildr.GetParseErrors(strParseErrors)<br>if bRetTemp = true then<br>   for l = 1 to UpperBound(strParseErrors)<br>      MessageBox ("Parse Error", strParseErrors[l])<br>   next<br>end if |
If parsing errors are found and GetParseErrors returns true,
a complete PBDOM node tree that can be inspected might still be
created.