AllowXmlAttribute (XmlDoc property): Difference between revisions
m (→Usage notes) |
m (→Examples) |
||
(13 intermediate revisions by 5 users not shown) | |||
Line 1: | Line 1: | ||
{{Template:XmlDoc:AllowXmlAttribute subtitle}} | {{Template:XmlDoc:AllowXmlAttribute subtitle}} | ||
The <var>AllowXmlAttribute </var> property indicates whether or not the method object <var>XmlDoc</var> allows the deserialization of an XML document that contains | The <var>AllowXmlAttribute </var> property indicates whether or not the method object <var>XmlDoc</var> allows the deserialization of an XML document that contains [[XmlDoc API#XmlDoc node types|Attribute nodes]] that begin with the character sequence <code>xml</code> (regardless of case), other than the standard prefixes of <code>xml:</code> or <code>xmlns:</code>. | ||
A <var>[[Enumerations#Using Boolean enumerations|Boolean]]</var> value of <var>True</var> allows such deserializations. The default value, <var>False</var>, cancels the request if such a deserialization is attempted. | |||
==Syntax== | ==Syntax== | ||
{{Template:XmlDoc:AllowXmlAttribute syntax}} | {{Template:XmlDoc:AllowXmlAttribute syntax}} | ||
Line 10: | Line 9: | ||
<table class="syntaxTable"> | <table class="syntaxTable"> | ||
<tr><th>%currentBoolean</th> | <tr><th>%currentBoolean</th> | ||
<td>The <var>Boolean</var> enumeration value of <var class="term">doc</var>'s <var>AllowXmlAttribute</var> property | <td>The <var>Boolean</var> enumeration value of <var class="term">doc</var>'s <var>AllowXmlAttribute</var> property. </td></tr> | ||
<tr><th>doc</th> | <tr><th>doc</th> | ||
<td>An <var>XmlDoc</var> object expression.</td></tr> | <td>An <var>XmlDoc</var> object expression.</td></tr> | ||
Line 20: | Line 19: | ||
<ul> | <ul> | ||
<li>Deserializing Attributes whose name begins with "xml" was restricted due to the following excerpt from the XML standard: | <li>Deserializing Attributes whose name begins with "xml" was restricted due to the following excerpt from the XML standard: | ||
<ul> | <ul class="nobul"> | ||
<li>Names beginning with the string "xml", or any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification. | <li>Names beginning with the string "xml", or any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification. | ||
</ul> | </ul> | ||
Therefore, you should use care with attribute names: using an attribute name which starts with "xml" makes you vulnerable to a change in the standards that would leave your document incompatible with them. | Therefore, you should use care with attribute names: using an attribute name which starts with "xml" makes you vulnerable to a change in the standards that would leave your document incompatible with them. | ||
'''Note:''' This property does not allow the <var>[[AddAttribute (XmlNode function)|AddAttribute]]</var> method to add an attribute with a name that starts with "xml". However, as shown in the [[#Adding an attribute to an element|"Adding an attribute to an element"]] example below, you can use the <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var>, <var>[[AddSubtree (XmlDoc/XmlNode_function)|AddSubtree]]</var>, and <var>[[DeleteSubtree_(XmlDoc/XmlNode_subroutine)|DeleteSubtree]]</var> methods to accomplish this. | <p class="note">'''Note:''' This property does not allow the <var>[[AddAttribute (XmlNode function)|AddAttribute]]</var> method to add an attribute with a name that starts with "xml". However, as shown in the [[#Adding an attribute to an element|"Adding an attribute to an element"]] example below, you can use the <var>[[LoadXml_(XmlDoc/XmlNode_function)|LoadXml]]</var>, <var>[[AddSubtree (XmlDoc/XmlNode_function)|AddSubtree]]</var>, and <var>[[DeleteSubtree_(XmlDoc/XmlNode_subroutine)|DeleteSubtree]]</var> methods to accomplish this. </p></li> | ||
</ul> | |||
==Examples== | ==Examples== | ||
===Displaying the property=== | ====Displaying the property==== | ||
The following example obtains the string value of the <var>AllowXmlAttribute</var> property: | The following example obtains the string value of the <var>AllowXmlAttribute</var> property: | ||
<p class="code">%str = %doc: | <p class="code">%str = %doc:allowXmlAttribute:ToString | ||
</p> | </p> | ||
Taking advantage of the implicit- | Taking advantage of the [[Enumerations#Usage Notes|implicit-ToString]] feature, you can print this value directly by using this: | ||
<p class="code">print %doc: | <p class="code">print %doc:allowXmlAttribute | ||
</p> | </p> | ||
===Deserializing an entire XML document=== | |||
====Deserializing an entire XML document==== | |||
The following request: | The following request: | ||
<p class="code">begin | <p class="code">begin | ||
Line 41: | Line 42: | ||
%d:allowXmlAttribute = true | %d:allowXmlAttribute = true | ||
%d:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<t xmlAtt="x">Test</t>') | %d:[[LoadXml_(XmlDoc/XmlNode_function)|loadXml]]('<t xmlAtt="x">Test</t>') | ||
[[PrintText statement|printText]]{~} is {%d:allowXmlAttribute} | [[PrintText statement|printText]] {~} is {%d:allowXmlAttribute} | ||
end | end | ||
</p> | </p> | ||
Displays: | |||
<p class="output">%d:allowXmlAttribute is True | |||
===Adding an attribute to an element=== | </p> | ||
====Adding an attribute to an element==== | |||
The following request: | The following request: | ||
<p class="code">begin | <p class="code">begin | ||
Line 61: | Line 64: | ||
end | end | ||
</p> | </p> | ||
Prints: | |||
<p class="output"><xyz xmlAtt="abc"/> | <p class="output"><xyz xmlAtt="abc"/> | ||
</p> | </p> | ||
==Request- | ==Request-cancellation errors (for set method)== | ||
This list is not exhaustive: it does <i>not</i> include all the errors that are request cancelling. | |||
<ul> | <ul> | ||
<li><var class="term">newBoolean</var> is an invalid value ( | <li>The <var class="term">newBoolean</var> argument is an invalid value (that is, not a <var>Boolean</var> value). | ||
</ul> | </ul> | ||
==See also== | ==See also== | ||
{{Template:XmlDoc:AllowXmlAttribute footer}} | {{Template:XmlDoc:AllowXmlAttribute footer}} |
Latest revision as of 19:43, 12 March 2014
May Attribute names begin with "xml"? (XmlDoc class)
[Introduced in Sirius Mods 7.9]
The AllowXmlAttribute property indicates whether or not the method object XmlDoc allows the deserialization of an XML document that contains Attribute nodes that begin with the character sequence xml
(regardless of case), other than the standard prefixes of xml:
or xmlns:
.
A Boolean value of True allows such deserializations. The default value, False, cancels the request if such a deserialization is attempted.
Syntax
%currentBoolean = doc:AllowXmlAttribute doc:AllowXmlAttribute = newBoolean
Syntax terms
%currentBoolean | The Boolean enumeration value of doc's AllowXmlAttribute property. |
---|---|
doc | An XmlDoc object expression. |
newBoolean | The Boolean value to assign to doc's AllowXmlAttribute property. |
Usage notes
- Deserializing Attributes whose name begins with "xml" was restricted due to the following excerpt from the XML standard:
- Names beginning with the string "xml", or any string which would match (('X'|'x') ('M'|'m') ('L'|'l')), are reserved for standardization in this or future versions of this specification.
Therefore, you should use care with attribute names: using an attribute name which starts with "xml" makes you vulnerable to a change in the standards that would leave your document incompatible with them.
Note: This property does not allow the AddAttribute method to add an attribute with a name that starts with "xml". However, as shown in the "Adding an attribute to an element" example below, you can use the LoadXml, AddSubtree, and DeleteSubtree methods to accomplish this.
Examples
Displaying the property
The following example obtains the string value of the AllowXmlAttribute property:
%str = %doc:allowXmlAttribute:ToString
Taking advantage of the implicit-ToString feature, you can print this value directly by using this:
print %doc:allowXmlAttribute
Deserializing an entire XML document
The following request:
begin %d object xmlDoc auto new %d:allowXmlAttribute = true %d:loadXml('<t xmlAtt="x">Test</t>') printText {~} is {%d:allowXmlAttribute} end
Displays:
%d:allowXmlAttribute is True
Adding an attribute to an element
The following request:
begin %d object xmlDoc auto new %n1 object xmlNode %n2 object xmlNode %n1 = %d:addElement('xyz') %d:allowXmlAttribute = true %n1:LoadXml('<junk xmlAtt="abc"/>') %n2 = %n1:SelectSingleNode('*/@*') %n1:AddSubtree(%n2) %n1:DeleteSubtree('*') %d:print end
Prints:
<xyz xmlAtt="abc"/>
Request-cancellation errors (for set method)
This list is not exhaustive: it does not include all the errors that are request cancelling.
- The newBoolean argument is an invalid value (that is, not a Boolean value).