Reading and Writing AIMMS-generated XML Data
Obtaining generated XML output
Through the functions
GenerateXML
(XMLFile,IdentifierSet[,merge][,SchemaFile])ReadGeneratedXML
(XMLFile[,merge])
AIMMS will generate XML output associated with one or more identifiers in your model, or read AIMMS-generated XML from a file.
The function GenerateXML
Using the function GenerateXML
, you can let AIMMS write XML data to
the file XMLFile. AIMMS will generate XML data for all the identifiers
in the IdentifierSet argument, which must be a subset of the
predefined set AllIdentifiers
. With the optional merge argument
(default 0) you can indicate whether you want to merge the generated XML
data in another XML document, in which case AIMMS will omit the XML
header from the generated XML file. This allows you to merge the
contents of the generated file into another XML file. Note that setting
the merge argument to 1 does not mean that the generated XML data will
be appended to the specified file, its contents are always completely
overwritten. If you specify a SchemaFile name, AIMMS will also
generate an XML schema file with the specified file name, matching the
generated XML data. All data in the XML file is represented in terms of
the currently active unit convention (see also
Globally Overriding Units Through Conventions). The function will return 1 if successful,
or 0 if not.
The function ReadGeneratedXML
With the function ReadGeneratedXML
you can read back AIMMS-generated
XML data from the specified XMLFile. With the optional merge
argument (default 0), you can choose whether you want to merge the data
included in the XML file with the existing data, or overwrite any
existing data (default). All data in the XML file will be interpreted in
accordance with the currently active unit convention (see also
Globally Overriding Units Through Conventions). The function will return 1 if successful,
or 0 if not.
Fixed format
The XML data format generated by the function GenerateXML
solely
depends on the declaration of the identifiers for which you want the XML
data to be generated. Thus, you can use the generated XML data simply to
store some model data in an XML file, ready to be read back into AIMMS
through the function ReadGeneratedXML
, or by any other program that
adheres to the XML data format as generated by AIMMS.
Example
A call to the function GenerateXML
, for the identifiers listed in
Introduction to XML Support in AIMMS, will result in the following XML data being
generated.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AimmsData>
<Flows>
<Flows elem="Inflow"/>
<Flows elem="Mix"/>
<Flows elem="NH3-Mix"/>
<Flows elem="NH3-Flow"/>
<Flows elem="Residue"/>
<Flows elem="Ar-Flow"/>
<Flows elem="Feedback"/>
</Flows>
<MeasuredFlow>
<f elem="Inflow" value="111.98"/>
<f elem="NH3-Flow" value="105.59"/>
<f elem="Feedback" value="358.00"/>
</MeasuredFlow>
<Flow>
<f elem="Inflow" value="117.03"/>
<f elem="Mix" value="475.03"/>
<f elem="NH3-Mix" value="475.03"/>
<f elem="NH3-Flow" value="105.59"/>
<f elem="Residue" value="369.44"/>
<f elem="Ar-Flow" value="11.44"/>
<f elem="Feedback" value="358.00"/>
</Flow>
<MeasuredComposition>
<nmf elem="Inflow">
<c elem="N2" value="26.96"/>
<c elem="H2" value="72.71"/>
<c elem="Ar" value="0.33"/>
</nmf>
<nmf elem="Mix">
<c elem="N2" value="24.56"/>
<c elem="Ar" value="4.91"/>
</nmf>
<nmf elem="NH3-Mix">
<c elem="N2" value="19.99"/>
</nmf>
<nmf elem="Residue">
<c elem="H2" value="69.68"/>
</nmf>
</MeasuredComposition>
<Composition>
<nmf elem="Inflow">
<c elem="N2" value="26.96"/>
<c elem="H2" value="72.71"/>
<c elem="Ar" value="0.33"/>
</nmf>
<nmf elem="Mix">
<c elem="N2" value="23.95"/>
<c elem="H2" value="71.08"/>
<c elem="NH3" value="0.05"/>
<c elem="Ar" value="4.91"/>
</nmf>
<nmf elem="NH3-Mix">
<c elem="N2" value="19.99"/>
<c elem="H2" value="59.08"/>
<c elem="NH3" value="15.27"/>
<c elem="Ar" value="5.66"/>
</nmf>
<nmf elem="NH3-Flow">
<c elem="NH3" value="100.00"/>
</nmf>
<nmf elem="Residue">
<c elem="N2" value="23.57"/>
<c elem="H2" value="69.68"/>
<c elem="NH3" value="0.07"/>
<c elem="Ar" value="6.67"/>
</nmf>
<nmf elem="Ar-Flow">
<c elem="N2" value="89.19"/>
<c elem="Ar" value="10.81"/>
</nmf>
<nmf elem="Feedback">
<c elem="N2" value="22.82"/>
<c elem="H2" value="70.48"/>
<c elem="NH3" value="0.07"/>
<c elem="Ar" value="6.62"/>
</nmf>
</Composition>
</AimmsData>
Numeric width and precision
Using the AIMMS options XML_number_width
and
XML_number_precision
you can specify the print width and precision
of any numerical data generated through the function GenerateXML
.
The rules are as follows.
If the option
XML_number_width
is set to \(-1\), AIMMS will always use scientific format with precisionXML_number_precision
.If the option
XML_number_width
is 0, AIMMS will print a fixed point floating point number with precisionXML_number_precision
, provided the number can be represented exactly with the given precision, otherwise scientific format will be used.If the option
XML_number_width
is greater than 0, AIMMS will print a fixed point floating point number with precisionXML_number_precision
, provided the number to be printed fits within the specified width, otherwise scientific format will be used.