ToXmlDoc (Record function): Difference between revisions

From m204wiki
Jump to navigation Jump to search
mNo edit summary
Line 16: Line 16:
</td></tr>
</td></tr>
<tr><th><var>AttributeValues</var></th>
<tr><th><var>AttributeValues</var></th>
<td>This name required argument (<var>AttributeValues</var>) is a boolean value that indicates whether a field value will be displayed as XML text or as an XML attribute (belonging to its field, which is displayed as an <var>XmlDoc</var> element).
<td>This [[Methods#Named parameters|name required]] argument (<var>AttributeValues</var>) is a <var>[[Enumerations#Using Boolean enumerations|Boolean]]</var> value that indicates whether a field value will be displayed as XML text or as an XML attribute (belonging to its field, which is displayed as an <var>XmlDoc</var> element).
For example, <code><APSUBUND>COMM</APSUBUND></code> is text format, and <code><APSUBUND value="COMM"/></code> is attribute value format.
For example, <code><APSUBUND>COMM</APSUBUND></code> is text format, and <code><APSUBUND value="COMM"/></code> is attribute value format.
The default value is <var>False</var>, which produces text format.
The default value is <var>False</var>, which produces text format.
</td></tr>
</td></tr>
<tr><th><var>AttributeNames</var></th>
<tr><th><var>AttributeNames</var></th>
<td>This name required argument (<var>AttributeNames</var>) is a boolean value that indicates whether field names are to be displayed within their XML document elements as the element name or as the value of a &amp;amp;amp;ldquo;name&amp;amp;amp;rdquo; attribute.
<td>This name required argument (<var>AttributeNames</var>) is a <var>Boolean</var> value that indicates whether field names are to be displayed within their XML document elements as the element name or as the value of a &amp;amp;amp;ldquo;name&amp;amp;amp;rdquo; attribute.
For example, <code><APSUBUND>COMM</APSUBUND></code> is element-name format, and the following is name-as-attribute format: <p class="code"> <field name="APSUBUND">    COMM  </field> </p>
For example, <code><APSUBUND>COMM</APSUBUND></code> is element-name format, and the following is name-as-attribute format: <p class="code"> <field name="APSUBUND">    COMM  </field> </p>
The default value as of <var class="product">Sirius Mods</var> version 7.6 (and maintenance back to version 7.3) is <var>True</var>, which produces name-as-attribute format. Formerly, the default value was <var>False</var>.
The default value as of <var class="product">Sirius Mods</var> version 7.6 (and maintenance back to version 7.3) is <var>True</var>, which produces name-as-attribute format. Formerly, the default value was <var>False</var>.
Line 28: Line 28:
</td></tr>
</td></tr>
<tr><th><var>NamesToLower</var></th>
<tr><th><var>NamesToLower</var></th>
<td>This name required argument (<code>NamesToLower</code>) is a boolean value that indicates whether field name data is to be displayed in lowercase characters. The default value is <code>False</code>, which produces uppercase output.
<td>This name required argument (<code>NamesToLower</code>) is a <var>Boolean</var> value that indicates whether field name data is to be displayed in lowercase characters. The default value is <code>False</code>, which produces uppercase output.
</td></tr>
</td></tr>
<tr><th><var>AllowUnreversible</var></th>
<tr><th><var>AllowUnreversible</var></th>
<td>This name required argument (<code>AllowUnreversible</code>) is a boolean value that indicates whether a request is cancelled if a field name would be changed irreversibly by lowercasing or by replacing with a period the characters that would be invalid in an XML document.
<td>This name required argument (<code>AllowUnreversible</code>) is a <var>Boolean</var> value that indicates whether a request is cancelled if a field name would be changed irreversibly by lowercasing or by replacing with a period the characters that would be invalid in an XML document.
For example, as described in [[#Usage Notes|"Usage Notes"]] below, fields FOO BAR and FOO%BAR would both produce the element name <code>FOO.BAR</code> if AttributeNames is set to <code>False</code>. This will cause request cancellation unless AllowUnreversible is set to <code>True</code>.
For example, as described in [[#Usage Notes|"Usage Notes"]] below, fields FOO BAR and FOO%BAR would both produce the element name <code>FOO.BAR</code> if AttributeNames is set to <code>False</code>. This will cause request cancellation unless AllowUnreversible is set to <code>True</code>.
The default value is <var>False</var>, which allows request cancellation to alert you about unreversible field names.
The default value is <var>False</var>, which allows request cancellation to alert you about unreversible field names.
</td></tr>
<tr><th><var>CodepageTable</var></th>
<td>This name required argument is a <var>Boolean</var> value; if <var>True</var>, the translations defined by the '''base''' Unicode codepage are used when translating from EBCDIC to Unicode for storing in the <var>XmlDoc</var>.
This argument is for the unusual case where you anticipate that the XML document is to be used later by <var>AddToRecord</var>, and the standard [[Unicode#Support for the ASCII subset of Unicode|Unicode translation tables]] in place when <var>AddToRecord</var> is invoked may differ from those in place when the record was copied to the <var>XmlDoc</var>.
The default value is <var>False</var>, which uses the standard Unicode translation tables, including any modifications specified in <code>UNICODE Trans</code> or <code>UNICODE Map</code> [[Unicode#Update forms of UNICODE|commands]].
The advantage of using <code>CodepageTable=False</code> is that it will allow you to readily modify the <var>XmlDoc</var> directly (that is, with the <var>[[AddElement (XmlDoc/XmlNode function)|AddElement]]</var> and <var>[[AddAttribute (XmlNode function)|AddAttribute]]</var> methods). Those operations will use the standard Unicode translation tables; there is no way to perform them using the base codepage translation tables.</td></tr>
<tr><th><var>AllowNull</var></th>


</td></tr></table>
<td>The value of this name required <var>Boolean</var> argument, which defaults to <var>False</var>, is copied to the <var>[[AllowNull (XmlDoc property)|AllowNull]]</var> property of the <var>XmlDoc</var> created by <var>ToXmlDoc</var>. The <var>XmlDoc</var>'s <var>AllowNull</var> property, in turn, determines whether field values that contain the X'00' character are stored in the <var>XmlDoc</var> with base64 encoding. Such values are base64 encoded if the <var>AllowNull</var> property is <var>False</var> (the default). For an example, see [[#Handling records with null characters|"Handling records with null characters"]] in the <var>[[NewFromRecord (XmlDoc function)|NewFromRecord]]</var> method description.
</td></tr>
</table>
==Usage notes==
==Usage notes==
<ul>
<ul>

Revision as of 00:04, 3 June 2011

Return in an XmlDoc the fields and values of the Record object's record (Record class)

[Requires Janus SOAP]

ToXmlDoc has options to display in uppercase or lowercase, as well as to output the values of the fields as XML attributes or as XML text of the field XML element.

ToXmlDoc is available in Sirius Mods version 7.3 and later.

Syntax

%doc = record:ToXmlDoc[( [AttributeValues= boolean], - [AttributeNames= boolean], [NamesToLower= boolean], - [AllowUnreversible= boolean], - [CodepageTable= boolean], [Base64Encode= boolean], - [CharacterMap= characterToUnicodeMap], - [AllowNull= boolean])] Throws CharacterTranslationException

Syntax terms

%doc An XmlDoc object variable to contain the record data.
%rec An instantiated Record object variable.
AttributeValues This name required argument (AttributeValues) is a Boolean value that indicates whether a field value will be displayed as XML text or as an XML attribute (belonging to its field, which is displayed as an XmlDoc element).

For example, <APSUBUND>COMM</APSUBUND> is text format, and <APSUBUND value="COMM"/> is attribute value format. The default value is False, which produces text format.

AttributeNames This name required argument (AttributeNames) is a Boolean value that indicates whether field names are to be displayed within their XML document elements as the element name or as the value of a &amp;amp;ldquo;name&amp;amp;rdquo; attribute. For example, <APSUBUND>COMM</APSUBUND> is element-name format, and the following is name-as-attribute format:

<field name="APSUBUND"> COMM </field>

The default value as of Sirius Mods version 7.6 (and maintenance back to version 7.3) is True, which produces name-as-attribute format. Formerly, the default value was False. The name-as-attribute format from the True option is better suited to operations on the XmlDoc, particularly a record copying operation. The element-name format from the False option is useful for displaying field names that are not valid as XML element names (for example, names with embedded spaces). For more information about handling non-valid XML names, see "Usage Notes", below.

NamesToLower This name required argument (NamesToLower) is a Boolean value that indicates whether field name data is to be displayed in lowercase characters. The default value is False, which produces uppercase output.
AllowUnreversible This name required argument (AllowUnreversible) is a Boolean value that indicates whether a request is cancelled if a field name would be changed irreversibly by lowercasing or by replacing with a period the characters that would be invalid in an XML document.

For example, as described in "Usage Notes" below, fields FOO BAR and FOO%BAR would both produce the element name FOO.BAR if AttributeNames is set to False. This will cause request cancellation unless AllowUnreversible is set to True. The default value is False, which allows request cancellation to alert you about unreversible field names.

CodepageTable This name required argument is a Boolean value; if True, the translations defined by the base Unicode codepage are used when translating from EBCDIC to Unicode for storing in the XmlDoc.

This argument is for the unusual case where you anticipate that the XML document is to be used later by AddToRecord, and the standard Unicode translation tables in place when AddToRecord is invoked may differ from those in place when the record was copied to the XmlDoc.

The default value is False, which uses the standard Unicode translation tables, including any modifications specified in UNICODE Trans or UNICODE Map commands.

The advantage of using CodepageTable=False is that it will allow you to readily modify the XmlDoc directly (that is, with the AddElement and AddAttribute methods). Those operations will use the standard Unicode translation tables; there is no way to perform them using the base codepage translation tables.
AllowNull The value of this name required Boolean argument, which defaults to False, is copied to the AllowNull property of the XmlDoc created by ToXmlDoc. The XmlDoc's AllowNull property, in turn, determines whether field values that contain the X'00' character are stored in the XmlDoc with base64 encoding. Such values are base64 encoded if the AllowNull property is False (the default). For an example, see "Handling records with null characters" in the NewFromRecord method description.

Usage notes

  • Whether to use ToXmlDoc, NewFromRecord, or LoadFromRecord depends on what is most convenient for your application. If you are already using a Record object which references the desired record, using ToXmlDoc may be more convenient; if not, then either LoadFromRecord or NewFromRecord (both of which require that the method be contained in a “record loop”) may be more convenient. You must use LoadFromRecord if you want to add the record's content as a subtree to a non-empty XmlDoc; in other cases the NewFromRecord “factory method” may be your choice.

    Since NewFromRecord and ToXmlDoc create new XmlDoc objects, they have the AllowNull argument for setting the created XmlDoc's AllowNull poperty; LoadFromRecord does not have the AllowNull argument.

    As stated, both NewFromRecord and LoadFromRecord must be contained in a “record loop”, for example, an FRN block, and they may not be invoked within a fieldgroup context.

    Except for these considerations, ToXmlDoc, NewFromRecord, and LoadFromRecord all perform the same operation and have the same arguments.

  • If any fields have name characters that are not valid when displayed as an XML element name, or if they have characters that are non-displayable when the name is formatted as an attribute value, the ToXmlDoc method converts the problematic characters to periods. For example, if field FOO BAR has value XXX, the AttributeNames parameter value is False, and the NamesToLower and AttributeValues parameters are set to True, the resulting display would be:

    <foo.bar value="XXX">

  • If NamesToLower is set to True, any field name containing lowercase characters is considered unreversible; reversing would involve converting the names to uppercase. To avoid request cancellation because of this, you must set to True the AllowUnreversible parameter.
  • If a field value contains non-displayable characters, the ToXmlDoc output data is automatically base64 encoded, and an attribute called encoding is added to the field's XML element with a value of base64. For example, consider this request:

    OPENC FILE ALEXQA b %r is object record in file alexqa %doc is object xmlDoc %r = new(3) %doc = %r:toXmlDoc(attributeNames=false, - attributeValues=true, - namestoLower=true) %doc:print print %doc:value('/Record/bar/@value') - :base64toString:stringToHex end

    If field BAR in record 3 contains X'00000040', the request might display this:

    <Record file="ALEXQA" number="3"> <foo value="ABC4"/> <bar value="AAAAQA==" encoding="base64"/> </Record> 00000040

  • The ToXmlDoc method will add BLOB values to the output XmlDoc, no matter how large they are. A BLOB field will have a reserved attribute added to the field element if more bytes were reserved in the BLOB than are in the actual value.
  • Typically, before they proceed, PAI, $list-fieldi, and other code that extracts fields by name from a record automatically get a share lock on a record if it appears to be unlocked. The ToXmlDoc method insists that the Record object be locked at least in share mode, therefore it gets no locks while it operates. No locks are required for a sorted record or in single-user mode.

Examples

The display of field data below is produced by the following request:

OPENC FILE CCASYS b %r is object record in file ccasys %r = new(1) %r:toXmlDoc:print %r:toXmlDoc(namesToLower=true):print %r:toXmlDoc(attributeValues=true):print %r:toXmlDoc(attributeValues=true, attributeNames=false, - namestoLower=true):print end

The following are sample results:

<Record file="CCASYS" number="1"> <field name="APSURTYP"> SDEF </field> <field name="APSUNM"> SUBSYSMGMT </field> <field name="APSUBUND"> COMM </field> <field name="APSUERRC"> ERROR </field> ... <Record file="CCASYS" number="1"> <field name="apsurtyp"> SDEF </field> <field name="apsunm"> SUBSYSMGMT </field> <field name="apsubund"> COMM </field> <field name="apsuerrc"> ERROR </field> ... <Record file="CCASYS" number="1"> <field name="APSURTYP" value="SDEF"/> <field name="APSUNM" value="SUBSYSMGMT"/> <field name="APSUBUND" value="COMM"/> <field name="APSUERRC" value="ERROR"/> ... <Record file="CCASYS" number="1"> <apsurtyp value="SDEF"/> <apsunm value="SUBSYSMGMT"/> <apsubund value="COMM"/> <apsuerrc value="ERROR"/> ...

See also