NewFromRecord (XmlDoc function): Difference between revisions
mNo edit summary |
mNo edit summary |
||
Line 11: | Line 11: | ||
===Syntax terms=== | ===Syntax terms=== | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%doc</th><td> | <tr><th>%doc</th><td><var>NewFromRecord</var> returns a new <var>XmlDoc</var> object.</td></tr> | ||
<tr><th><var>%(XmlDoc)</var></th> | <tr><th><var>%(XmlDoc)</var></th> | ||
<td>The class name in parentheses denotes a shared method and is one way to invoke <var>NewFromRecord</var>. You can also use an object expression whose type is <var>XmlDoc</var> (even if the value of the expression is null).</td></tr> | <td>The class name in parentheses denotes a shared method and is one way to invoke <var>NewFromRecord</var>. You can also use an object expression whose type is <var>XmlDoc</var> (even if the value of the expression is null).</td></tr> | ||
Line 25: | Line 25: | ||
<td>Boolean object</td></tr> | <td>Boolean object</td></tr> | ||
<tr><th><var>AllowNull</var></th> | <tr><th><var>AllowNull</var></th> | ||
<td>Boolean | <td>The value of this [[Enumerations#Using Boolean enumerations|Boolean]] 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>NewFromRecord</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). | ||
A <var>False</var> value prevents null characters from being stored in the <var>XmlDoc</var>, so | |||
it will conform to the XML Recommendation, which does not allow null characters in an XML document. | |||
The following fragment: | |||
<p class="code"><nowiki>%s = 'Field with null/' With '00':X With '/' | |||
Store Record | |||
FOO = %s | |||
End Store | |||
%r = $CurRec | |||
FRN %r | |||
%doc = %doc:NewFromRecord | |||
End For | |||
PrintText {~} = {%doc:AllowNull} | |||
%doc:Print | |||
</nowiki></p> | |||
produces this output: | |||
<p class="output"><nowiki>%doc:AllowNull = False | |||
<Record version="1" file="QAWORK" number="1"> | |||
<field name="FOO" encoding="base64"> | |||
xomFk4RApomjiECVpJOTYQBh | |||
</field> | |||
</Record> | |||
</nowiki></p> | |||
In the above output, notice that <code>FOO</code> is base64 encoded, | |||
because it contains a null character, and | |||
null characters are not allowed in an <var>XmlDoc</var> whose <var>AllowNull</var> | |||
property is <var>False</var>. | |||
The following fragment: | |||
<p class="code"><nowiki>%s = 'Field with null/' With '00':X With '/' | |||
Store Record | |||
FOO = %s | |||
End Store | |||
%r = $CurRec | |||
FRN %r | |||
%doc = %doc:NewFromRecord(AllowNull=True) | |||
End For | |||
PrintText {~} = {%doc:AllowNull} | |||
%doc:Print | |||
</nowiki></p> | |||
produces the following output: | |||
<p class="output"><nowiki>%doc:AllowNull = True | |||
<Record version="1" file="QAWORK" number="1"> | |||
<field name="FOO"> | |||
Field with null/&#x0;/ | |||
</field> | |||
</Record> | |||
</nowiki></p> | |||
In the above output, <code>FOO</code> is not base64 encoded; the <var>XmlDoc</var> contains | |||
a null character, which is displayed by the <var>Print</var> method using a | |||
character reference (<code>&#x0;</code>). | |||
This may be useful for visually inspecting the contents of the | |||
<var>XmlDoc</var>, again noting that such a document is not, strictly speaking, | |||
conformant to the XML Recommendation. | |||
<p> | |||
See the description of the <var>AttributeValue</var> argument of the [[#LoadFromRecord subroutine in XmlDoc and XmlNode classes|LoadFromRecord subroutine]] for a list of all conditions which force base64 encoding of the "field" element.</p></td></tr> | |||
</table> | </table> | ||
Line 57: | Line 117: | ||
==Examples== | ==Examples== | ||
==See also== | ==See also== | ||
<ul> | |||
<li>See the <var>[[LoadFromRecord (XmlDoc/XmlNode subroutine)|LoadFromRecord]]</var> method for a discussion of extracting the contents of the current record into an <var>XmlDoc</var>. | |||
</ul> | |||
{{Template:XmlDoc:NewFromRecord footer}} | {{Template:XmlDoc:NewFromRecord footer}} |
Revision as of 23:06, 1 June 2011
Create a new XmlDoc from the current record (XmlDoc class)
[Requires Janus SOAP]
This shared function creates a new XmlDoc object that contains the fields and fieldgroups from the current record. This record extraction is the same operation that is performed by the LoadFromRecord subroutine and by the ToXmlDoc function in the Record class.
Syntax
%doc = [%(XmlDoc):]NewFromRecord[( [AttributeValues= boolean], - [AttributeNames= boolean], - [NamesToLower= boolean], - [AllowUnreversible= boolean], - [CodepageTable= boolean], - [Base64Encode= boolean], - [CharacterMap= characterToUnicodeMap], - [Allownull= boolean], - [Recordnumber= number], [File= string])] Throws CharacterTranslationException
Syntax terms
%doc | NewFromRecord returns a new XmlDoc object. |
---|---|
%(XmlDoc) | The class name in parentheses denotes a shared method and is one way to invoke NewFromRecord. You can also use an object expression whose type is XmlDoc (even if the value of the expression is null). |
AttributeValues | Boolean object |
AttributeNames | Boolean object |
NamesToLower | Boolean object |
AllowUnreversible | Boolean object |
CodepageTable | Boolean object |
AllowNull | The value of this Boolean argument, which defaults to False, is copied to the AllowNull property of the XmlDoc created by NewFromRecord. 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).
A False value prevents null characters from being stored in the XmlDoc, so it will conform to the XML Recommendation, which does not allow null characters in an XML document. The following fragment: %s = 'Field with null/' With '00':X With '/' Store Record FOO = %s End Store %r = $CurRec FRN %r %doc = %doc:NewFromRecord End For PrintText {~} = {%doc:AllowNull} %doc:Print produces this output: %doc:AllowNull = False <Record version="1" file="QAWORK" number="1"> <field name="FOO" encoding="base64"> xomFk4RApomjiECVpJOTYQBh </field> </Record> In the above output, notice that %s = 'Field with null/' With '00':X With '/' Store Record FOO = %s End Store %r = $CurRec FRN %r %doc = %doc:NewFromRecord(AllowNull=True) End For PrintText {~} = {%doc:AllowNull} %doc:Print produces the following output: %doc:AllowNull = True <Record version="1" file="QAWORK" number="1"> <field name="FOO"> Field with null/�/ </field> </Record> In the above output, See the description of the AttributeValue argument of the LoadFromRecord subroutine for a list of all conditions which force base64 encoding of the "field" element. |
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
NewFromRecord or LoadFromRecord (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. The discussion of the “extract from record to XmlDoc” operation, generally uses LoadFromRecord, except where one of these considerations is relevant to the discussion.
Examples
See also
- See the LoadFromRecord method for a discussion of extracting the contents of the current record into an XmlDoc.