66
In[9]:=
sym = ImportString@ xml, "XML"D
Out[9]=
XMLObject@DocumentD@8XMLObject@DeclarationD@Version O 1.0D<, XMLElement@library,
8<, 8XMLElement@book, 8<, 8XMLElement@title, 8<, 8A New Kind of Science
XMLElement@author, 8<, 8Stephen Wolfram
XMLElement@book, 8<, 8XMLElement@title, 8<, 8The Lord of the Rings
XMLElement@author, 8<, 8J.R.R. Tolkien 8
We can use standard Mathematica programming features to process Symbolic XML; for example, we can extract all
the authors.
In[10]:=
Cases@sym, XMLElement@ "author", a_, 8d_ O d, InfinityD
Out[10]=
8Stephen Wolfram, J.R.R. Tolkien<
In[16]:=
newSym = sym e. XMLElement@ t_, a_, 8d_ O XMLElement@t, a, 8ToLowerCase@dD
Out[16]=
XMLObject@DocumentD@8XMLObject@DeclarationD@Version O 1.0D<, XMLElement@library,
8<, 8XMLElement@book, 8<, 8XMLElement@title, 8<, 8a new kind of science
XMLElement@author, 8<, 8stephen wolfram
XMLElement@book, 8<, 8XMLElement@title, 8<, 8the lord of the rings
XMLElement@author, 8<, 8j.r.r. tolkien 8
Here we generate a new XML format that was formed by modifying the original input.
In[17]:=
ExportString@newSym, "XML"D
Out[17]=
version= 1.0 ?>
a new kind of science
stephen wolfram
the lord of the rings
j.r.r. tolkien
This type of transformation can of course be done in other ways. For example, the use of XSLT stylesheet technol
ogy provides one way. However, there is an overhead to setting up an XSLT stylesheet to make the transformation.
The use of Mathematica, with its uniform programming principles, is often a quick and simple way to get the task
carried out.
There are many more features of the Mathematica XML tools, for example, working with attributes, entities,
namespaces, validation, and CDATA. More information is available from the Mathematica documentation.
5.1.3 webMathematica XML Applications
Many webMathematica applications involve generating HTML to be read by browsers. However, the output from a
webMathematica site may not go to a browser; it may involve some data to be read by an application that will then
do further processing. This section will study an example that shows how this can be done.
.
<
New Page 1
Comcast Web Hosting