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 2 |
PBDOM_BUILDER pbdom_builder_new PBDOM_DOCUMENT pbdom_doc |
The objects are then instantiated using the constructor and the
PBDOM_BUILDER BuildFromString method:
|
1 2 |
pbdombuilder_new = Create PBDOM_Builder pbdom_doc = pbdombuilder_new.BuildFromString(Xml_doc) |
XML can also be loaded directly into a string variable, as in the
following example:
|
1 2 3 4 5 6 7 |
string Xml_str Xml_str = "<?xml version="1.0" ?>" Xml_str += "<WHITEPAPER>" Xml_str += "<TITLE>Document Title</TITLE>" Xml_str += "<AUTHOR>Author Name</AUTHOR>" Xml_str += "<PARAGRAPH>Document text.</PARAGRAPH>" 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 2 3 4 5 |
PBDOM_BUILDER pbdombuilder_new PBDOM_DOCUMENT pbdom_doc pbdombuilder_new = Create PBDOM_Builder pbdom_doc = pbdombuilder_new.BuildFromFile & ("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 2 3 4 5 6 7 8 9 10 |
PBDOM_Builder pbdom_bldr pbdom_document pbdom_doc datastore ds ds = Create datastore ds.DataObject = "d_customer" ds.SetTransObject (SQLCA) ds.Retrieve pbdom_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 2 3 4 5 6 7 8 9 10 11 12 13 |
PBDOM_Builder pbdom_bldr pbdom_document pbdom_doc string strParseErrors[] BOOLEAN bRetTemp = FALSE pbdom_buildr = Create PBDOM_BUILDER pbdom_doc = pbdom_buildr.BuildFromFile("D: emp.xml") bRetTemp = pbdom_buildr.GetParseErrors(strParseErrors) if bRetTemp = true then for l = 1 to UpperBound(strParseErrors) MessageBox ("Parse Error", strParseErrors[l]) next end if |
Parsing errors
If parsing errors are found and GetParseErrors returns true, a
complete PBDOM node tree that can be inspected might still be
created.