XML Utilities
In addition to HTML conversion, XMLUtils has a number of utilities to search and manipulate ⎕XML's 5-column matrix format. This page presents only descriptions of the utilities. Examples are found on the examples page.
Xfind
Xfind finds XML elements matching criteria you specify. The criteria maps closely to the columns of a ⎕XML matrix.
| Syntax | bv ← xml Xfind criteria |
criteria |
A delimited character vector where each segment is a filter to be applied to a column of xml. The first character in criteria is used as the delimiter. Empty segments are not used in the search. All textual searches are case insensitive.specs ← '/level/element/content/attribute/attributeValue/type'Where:
|
xml |
A 5-column ⎕XML matrix |
bv |
A Boolean vector marking rows in xml that match the search criteria in criteria |
Xselect
Having found XML elements using Xfind, you can use Xselect to select them and optionally their immediate descendants.
| Syntax | elements ← {kids} (xml Xselect) bv |
bv |
A Boolean vector with as many elements as rows in xml. 1's indicate an element to retrieve. |
xml |
A 5-column ⎕XML matrix |
kids |
An optional Boolean scalar indicating whether to in include descendent elements. Valid values are:
|
elements |
A vector containing +/bv elements, each of which contains the xml element corresponding to a 1 in bv and, if kids is 1, its immediately following descendant elements. |
Xattr
Xattr retrieves the values of all attributes in xml that match the attribute name(s) you supply.
| Syntax | values ← {ic} (xml Xattr) attr |
attr |
A vector of space-separated attribute names, or a vector of such vectors. |
xml |
A single 5-column ⎕XML-style matrix or vector of such matrices |
ic |
An optional Boolean indicating whether to perform a case-insensitive comparison on the attribute names. Valid values are:
|
values |
The shape of values depends on the shapes of xml and attr.
|
| Notes | XML and XHTML attribute names are case sensitive, while HTML attribute names are not. |
Xattrval
Xattrval is a shortcut function that essentially does an Xfind, Xselect, and Xattr.
| Syntax | values ← {ic} (xml Xattrval) criteria |
criteria |
The same as criteria described in Xfind above.A delimited character vector where each segment is a filter to be applied to a column of xml. Empty segments are not used in the search. All textual searches are case insensitive.specs ← '/level/element/content/attribute/attributeValue/type'Where:
|
xml |
A single 5-column ⎕XML matrix |
ic |
An optional Boolean indicating whether to perform a case-insensitive comparison on the attribute names. Valid values are:
|
values |
The shape of values depends on the shapes of xml and attr.
|
| Notes | XML and XHTML attribute names are case sensitive, while HTML attribute names are not. |
Xdelete
Xdelete deletes elements and optionally their descendants from an XML structure
| Syntax | r ← {kids} (xml Xdelete) criteria |
criteria |
Either the same as criteria described in Xfind above or a Boolean vector marking the elements to be deleted |
xml |
Either a single 5-column ⎕XML matrix, or a string containing valid XML |
kids |
An optional Boolean indicating whether to delete just the elements specified in criteria or their descendants as well. Valid values are:
|
r |
The resulting 5-column ⎕XML matrix after the elements have been deleted |
Xinsert
Xinsert inserts elements after selected elements
| Syntax | r ← ins (xml Xinsert) elements |
elements |
Either the same as criteria described in Xfind above or a Boolean vector marking the elements after which the new content will be inserted |
xml |
Either a single 5-column ⎕XML matrix, or a string containing valid XML |
ins |
Either a single 5-column ⎕XML matrix, or a string containing valid XML to be inserted |
r |
The resulting 5-column ⎕XML matrix after the elements have been inserted |
Xreplace
Xreplace replaces XML elements and their descendents
| Syntax | r ← repl (xml Xreplace) elements |
elements |
Either the same as criteria described in Xfind above or a Boolean vector marking the elements to be replaced |
xml |
Either a single 5-column ⎕XML matrix, or a string containing valid XML |
repl |
Either a single 5-column ⎕XML matrix, or a string containing valid XML to be inserted |
r |
The resulting 5-column ⎕XML matrix after the elements have been inserted |