|
Representing Elements
Each element in an XML document corresponds to an XMLElement command in SymbolicXML. An XML expression of the form
<element attribute='value'> data </element>
has the following representation in SymbolicXML.
XMLElement[element,{attribute value},{data}]
Each XMLElement[] command has three arguments:
- The first argument specifies the name of the element.
- The second argument specifies the attributes of the element. This argument is a list of zero or more rules, with each rule specifying a single attribute in the form: attribute
value.
- The third argument specifies the actual data contained in the element. This can be raw character data in the form of a string and/or child elements of the element being represented. Each child element is represented by its own XMLElement[] command. You can nest multiple XMLElement[] commands to the level necessary to replicate the nested structure of the original XML expression.
The names of all elements and attributes as well as any character data in the XML document are represented as strings in SymbolicXML. This is to prevent a large number of new symbols from being introduced into the Mathematica session, which could lead to possible naming conflicts.
Here is a simple XML fragment.
<book type='novel'>Moby Dick</book>
Here is the representation of this fragment in SymbolicXML.
XMLElement["book",{"type" "novel"},{"Moby Dick"}]
Here is a more complicated XML expression, showing several levels of nesting.
<book type='novel'>
<title>Moby Dick</title>
<author born='1819' died='1891'>
<name>
<first>Herman</first>
<last>Melville</last>
</name>
</author>
</book>
Here is the corresponding SymbolicXML expression.
XMLElement["book",{"type" "novel"},{
XMLElement["title",{},{"Moby Dick"}],
XMLElement["author",{"born" "1819","died" "1891"},{
XMLElement["name",{},{
XMLElement["first",{},{"Herman"}],
XMLElement["last",{},{"Melville"}]}]}]}]
|