XMLParseString PowerScript function
Description
Parses an XML string and determines whether the string is
well formed or complies with a specified grammar.
Syntax
|
1 |
<span>XMLParseString</span> ( <span>xmlstring</span> {, <span>validationscheme</span> }{, <span>parsingerrors</span> } {, <span>namespaceprocessing</span> {, <span>schemaprocessing</span> {, <span>schemafullchecking</span> }}}) |
|
Argument |
Description |
|---|---|
|
xmlstring |
A string that holds the XML document |
|
validationscheme (optional) |
A value of the ValSchemeType enumerated
|
|
parsingerrors (optional) |
A string buffer to which error messages |
|
namespaceprocessing (optional) |
A boolean specifying whether name space If validationscheme is set to ValAlways! The default is false. |
|
schemaprocessing (optional) |
A boolean specifying whether schema support If schemaprocessing is true, namespaceprocessing must also The default is false. |
|
schemafullchecking (optional) |
A boolean specifying whether schema constraints Setting schemafullchecking to true has The default is false. |
Return Values
Long. Returns 0 for success and one of
the following negative values if an error occurs:
-
-1 Parsing error
-2 Argument error
Usage
Use XMLParseString to validate an XML string
against a DTD or XML schema before proceeding with additional processing.
If no DTD or schema is included or referenced in the string, XMLParseString checks
whether the string contains well-formed XML. If the XML string fails validation
or is not well–formed, XMLParseString returns
-1.
XSD (schema) files are in XML format and you can check them
for well–formedness. The validation scheme must be ValAuto!,
which is the default validation scheme, because ValAlways! requires
that there be a schema or DTD against which to validate the file.
For example, given the following schema file, the parser fails
because there is no external XSD file that defines xs:schema, xs:element,
and xs:complextype. The
schema is defined by the namespace http://www.w3.org/2001/XMLSchema.
|
1 |
<?xml version="1.0" encoding="UTF-8"?><br>  <xs:schema xmlns:xs=<br>                 "http://www.w3.org/2001/XMLSchema"><br>     <xs:element name="test3"><br>       <xs:complexType><br>          <xs:sequence><br>             <xs:element ref="test3_row" maxOccurs=<br>                           "unbounded" minOccurs="0"/><br>          </xs:sequence><br>       </xs:complexType><br>     </xs:element><br>  </xs:schema> |
Using ValAlways! also fails for an XML file if there is no
schema defined or the reference does not point to a valid schema.
If you use ValAuto!, validation is performed only if the schema
or DTD file is present in the desired location. If it is not present,
only well-formedness is checked.To suppress the display of message
boxes if errors occur, specify a string value for the parsingerrors argument.
The files pbxercesNN.dll and xerces-c_XX.dll,
where NN represents the PowerBuilder version
and XX represents the Xerces version, must
be deployed with the other PowerBuilder runtime files in the search
path of any application or component that uses this function.
Examples
These statements parse an XML string. If a DTD is
included or referenced, the string is validated. Otherwise the parser
checks for well-formedness:
|
1 |
// string argument as_xmlstring passed in<br>long ll_ret<br> <br>ll_ret = XMLParseString(as_xmlstring) |
These statements parse an XML string, validate against a given
XML schema, and save any errors that occur in a string variable.
If errors occur, no message boxes display. If no schema is included
or referenced in the string, XMLParseString returns
-1:
|
1 |
long ll_ret<br>string ls_xmlstr, ls_err<br> <br>ll_ret = XMLParseString(ls_xmlstr, ValAlways!,<br>   ls_err, TRUE, TRUE) |
These statements parse an XML string, validate against a given
DTD, and save any errors that occur in a string variable. If errors
occur, no message boxes display. If no DTD is included or referenced
in the string, XMLParseString returns –1.
If the string passes validation, it is imported into a DataWindow control:
|
1 |
long ll_ret<br>string ls_xmlstr, ls_err<br> <br>ll_ret = XMLParseString(ls_xmlstr, ValAlways!, ls_err)<br>if ll_ret = 1 then dw_1.ImportString(ls_xmlstr) |
See Also
-
ImportString in the DataWindow
Reference or online Help