ProcessAttributes - Maple Help

XMLTools

 ProcessAttributes
 process the attributes of an XML element

 Calling Sequence ProcessAttributes(xmlTree, Allowable, Values, Options)

Parameters

 xmlTree - Maple XML tree; XML element Allowable - set of strings; attribute names that are valid for xmlTree Values - table; on exit, contains an entry for each attribute value indexed by the attribute name Options - (optional) equations of the form option_name = option_value; error-checking options

Description

 • The ProcessAttributes(xmlTree, Allowable, Values, Options) command processes the attributes of xmlTree by assigning any attribute values to Values (a table created by ProcessAttributes and indexed by the attribute names). The Allowable argument is a set of those attribute names, which are valid for xmlTree.
 • ProcessAttributes can also perform rudimentary error checking when Options are included in the calling sequence. These Options specify whether to return an error or ignore any problems in the attributes.
 The following options are permitted in the calling sequence.
 required =set of strings
 Specifies a set of strings, which must be a subset of the set Allowable. If an attribute in this set does not have an assigned value, an exception occurs.
 name =symbol
 Checks that xmlTree has the given name. The name must not have the _XML_ prefix.
 The string specified by this option is appended to any error messages that are generated.
 validate =truefalse
 Specifies whether an error is returned if there is a ever a problem with an attribute (that is, either xmlTree contains an attribute which is not expected or it does not have a value for a required attribute).
 The default setting for this option is false. Therefore, if this option is not specified or if validate = false is included in the calling sequence, then an error is not returned if a problem with an attribute occurs. Otherwise, if this option is specified as true, an error is returned when a problem with an attribute occurs.
 Note: This does not mean that errors in arguments to ProcessAttributes are ignored. For example, if the required option has an attribute name that is not contained in the set Allowable, an exception still occurs.
 defaults =equation or set of equations
 Specifies the default attribute value for any attribute. Each equation must take the form $\mathrm{attrName}=\mathrm{attrValue}$, where attrName and attrValue are both strings. All left-hand sides of the equations must be members of the set Allowable.

Examples

 > $\mathrm{with}\left(\mathrm{XMLTools}\right):$
 > $\mathrm{xml}≔\mathrm{ParseString}\left("3a53"\right):$
 > $\mathrm{MyContent}≔\mathrm{ProcessAttributes}\left(\mathrm{xml},\left\{"class","id","other","style","xref","definitionURL","encoding"\right\},\mathrm{AttributeValues},'\mathrm{name}'='\mathrm{set}','\mathrm{error_addendum}'="MathML 2.0 4.4.6.1"\right)$
 ${\mathrm{MyContent}}{≔}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"cn"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"type"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"integer"}\right)\right)\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"3"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"ci"}\right){,}\left[\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"a"}\right)\right]\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"cn"}\right){,}\left[{\mathrm{_XML_Attribute}}{}\left({\mathrm{_XML_AttrName}}{}\left({"type"}\right){,}{\mathrm{_XML_AttrValue}}{}\left({"rational"}\right)\right)\right]{,}\left[{\mathrm{_XML_Text}}{}\left({"5"}\right){,}{\mathrm{_XML_Element}}{}\left({\mathrm{_XML_ElementType}}{}\left({"sep"}\right){,}\left[\right]{,}\left[\right]\right){,}{\mathrm{_XML_Text}}{}\left({"3"}\right)\right]\right)$ (1)
 > $\mathrm{AttributeValues}\left["id"\right]$
 ${"0203"}$ (2)