Writes an XML document from a ProDataSet, temp-table, or temp-table buffer object. In the case of the temp-table buffer object, all the records of the temp-table associated with the buffer object are written to the XML document—not just the one in the buffer. You can write the XML representation of the object with data, schema, or both. If you include schema, it is written using the XML Schema Definition (XSD) language.
WRITE-XML ( target-type
, { file | stream | stream-handle | memptr | handle | longchar }
[ , formatted [ , encoding [ , schema-location [ , write-xmlschema
[ , min-xmlschema [ , write-before-image [ , omit-initial-values
] ] ] ] ] ] ] )
|
If target-type is
"HANDLE", the X-document’s ENCODING attribute is also set.
An optional CHARACTER expression that specifies the name of an external XML Schema file. The method uses this value to set the
xsi:schemaLocation or
xsi:noNamespaceSchemaLocation attribute in the XML document. If the ProDataSet or temp-table object’s NAMESPACE-URI attribute is the empty string (
"") or the Unknown value (
?), the method adds the
xsi:noNamespaceSchemaLocation attribute in the XML document and sets it to this value. If the NAMESPACE-URI attribute is not the empty string (
"") or the Unknown value (
?), the method adds the
xsi:schemaLocation attribute to the XML document with a value of
"namespace-uri<space>schema-location". The default value is the Unknown value (
?).
If you specify write-xmlschema as TRUE, you cannot specify
schema-location.
If you specify TRUE, you cannot specify schema-location. If you specify FALSE, you must also specify
min-xmlschema as FALSE. If you specify the Unknown value (
?), the method uses the default value of FALSE.
Note:
|
If you specify TRUE and the NAMESPACE-URI attribute value for a temp-table buffer within a ProDataSet object is different than that of the ProDataSet object, the method creates a separate XML Schema file for the temp-table definition. The namespace URI for the temp-table is imported into the ProDataSet schema, with a schemaLocation pointing to a separate XML Schema file containing the temp-table definition. Multiple namespaces are supported only when target-type is "FILE". If the ProDataSet object contains multiple namespaces and target-type is not "FILE", the method generates an error and returns FALSE.
|
An optional LOGICAL expression where TRUE directs the AVM to write the minimum amount of schema when it writes the XML Schema representation of the object, and FALSE directs the AVM to write the complete schema including ABL-specific schema attributes. The default value is FALSE. If you specify the Unknown value (
?), the method uses the default value of FALSE.
When TRUE, ABL-specific schema information (such as, field format, non-unique indexes, and so on) is omitted from the XML Schema. If the ABL data type of the temp-table field is not the default ABL data type for the XML Schema type, the AVM writes the
prodata:dataType XML Schema attribute for the field. If the initial value of the temp-table field is TODAY, NOW, or UNKNOWN (and UNKNOWN is not the default initial value for the field’s data type), the AVM writes the
prodata:initial XML Schema attribute for the field.
If you specify write-xmlschema as FALSE, you must also specify
min-xmlschema as FALSE.
Although using the omit-initial-values option can give your application performance and resource use improvements, you need to be sure that the consumers of the generated XML document will correctly handle the XML. The ABL READ-XML( ) method will always populate created records with initial values from the temp-table or ProDataSet definition. Other applications might not do this.
For example, .NET can read an XML Schema and XML data document into a dynamic ADO .NET DataSet using its
ReadXmlSchema( ) and
ReadXml( ) APIs, but missing elements are always interpreted as a null (the Unknown value (
?) in ABL terms) DataColumn in the DataTable. They do recognize the initial value definition in the XML Schema when creating rows in the DataTable directly (initial value in the XML Schema gets translated to the
DefaultValue property on the DataColumn), but do not with
ReadXml( ).
Note:
|
When executing the WRITE-XML( ) method on a temp-table or ProDataSet, and the default buffer of one of the contained temp-tables is available, there is no guarantee as to the state of that buffer after the method finishes executing. The record buffer may not be available. If default buffer availability is an issue, it is suggested that a named buffer be used with this method. A named buffer can be created with the DEFINE BUFFER statement.
|
DEFINE VARIABLE cTargetType AS CHARACTER NO-UNDO.
DEFINE VARIABLE cFile AS CHARACTER NO-UNDO.
DEFINE VARIABLE lFormatted AS LOGICAL NO-UNDO.
DEFINE VARIABLE cEncoding AS CHARACTER NO-UNDO.
DEFINE VARIABLE cSchemaLocation AS CHARACTER NO-UNDO.
DEFINE VARIABLE lWriteSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE lMinSchema AS LOGICAL NO-UNDO.
DEFINE VARIABLE lRetOK AS LOGICAL NO-UNDO.
DEFINE TEMP-TABLE ttCustomer NO-UNDO LIKE Customer.
DEFINE TEMP-TABLE ttOrder NO-UNDO LIKE Order.
DEFINE TEMP-TABLE ttInvoice NO-UNDO LIKE Invoice.
DEFINE DATASET DSET FOR ttCustomer, ttOrder, ttInvoice
DATA-RELATION CustOrd FOR ttCustomer,
ttOrd RELATION-FIELDS(CustNum,CustNum) NESTED
DATA-RELATION OrdInv FOR ttOrder,
ttInv RELATION-FIELDS(OrderNum,OrderNum) NESTED.
DEFINE DATA-SOURCE dsCustomer FOR Customer.
DEFINE DATA-SOURCE dsOrder FOR Order.
DEFINE DATA-SOURCE dsInvoice FOR Invoice.
BUFFER ttCustomer:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsCustomer:HANDLE).
BUFFER ttOrder:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsOrder:HANDLE).
BUFFER ttInvoice:HANDLE:ATTACH-DATA-SOURCE(DATA-SOURCE dsInvoice:HANDLE).
DATA-SOURCE dsCustomer:FILL-WHERE-STRING = "WHERE Customer.CustNum = 2 ".
DATASET DSET:FILL().
ASSIGN
cTargetType = "file"
cFile = "dset.xml"
lFormatted = TRUE
cEncoding = ?
cSchemaLocation = ?
lWriteSchema = FALSE
lMinSchema = FALSE.
lRetOK = DATASET DSET:WRITE-XML(cTargetType, cFile, lFormatted, cEncoding,
cSchemaLocation, lWriteSchema, lMinSchema).
|
See also:
|
ENCODING attribute, FIX-CODEPAGE statement, FOREIGN-KEY-HIDDEN attribute, NAMESPACE-PREFIX attribute, NAMESPACE-URI attribute, NESTED attribute, READ-XML( ) method, READ-XMLSCHEMA( ) method, SERIALIZE-ROW( ) method, SERIALIZE-HIDDEN attribute, SERIALIZE-NAME attribute, SERIALIZE-ROW( ) method, WRITE-XMLSCHEMA( ) method, XML-NODE-NAME attribute, XML-NODE-TYPE attribute
|