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</b> <b>new</b> <b>kind</b> <b>of</b> <b>science<etitle></b></font></pre></span>
<span name = "INTRA" style='top:697px; left:225px' class="ft1"><pre><font face='Arial'><b><author>stephen</b> <b>wolfram<eauthor></b></font></pre></span>
<span name = "INTRA" style='top:716px; left:216px' class="ft1"><pre><font face='Arial'><b><ebook></b></font></pre></span>
<span name = "INTRA" style='top:735px; left:216px' class="ft1"><pre><font face='Arial'><b><book></b></font></pre></span>
<span name = "INTRA" style='top:754px; left:225px' class="ft1"><pre><font face='Arial'><b><title>the</b> <b>lord</b> <b>of</b> <b>the</b> <b>rings<etitle></b></font></pre></span>
<span name = "INTRA" style='top:773px; left:225px' class="ft1"><pre><font face='Arial'><b><author>j.r.r.</b> <b>tolkien<eauthor></b></font></pre></span>
<span name = "INTRA" style='top:791px; left:216px' class="ft1"><pre><font face='Arial'><b><ebook></b></font></pre></span>
<span name = "INTRA" style='top:811px; left:207px' class="ft1"><pre><font face='Arial'><b><elibrary></b></font></pre></span>
<span name = "INTRA" style='top:849px; left:129px' class="ft1"><pre><font face='Arial'><b>This type of transformation can of course be done in other ways. For example, the use of XSLT stylesheet technol </b></font></pre></span>
<span name = "INTRA" style='top:867px; left:129px' class="ft1"><pre><font face='Arial'><b>ogy provides one way. However, there is an overhead to setting up an XSLT stylesheet to make the transformation.</b></font></pre></span>
<span name = "INTRA" style='top:886px; left:129px' class="ft1"><pre><font face='Arial'><b>The use of Mathematica, with its uniform programming</b> <b> principles, is often a quick and simple</b> <b> way to get the task</b></font></pre></span>
<span name = "INTRA" style='top:904px; left:129px' class="ft1"><pre><font face='Arial'><b>carried out.</b></font></pre></span>
<span name = "INTRA" style='top:943px; left:129px' class="ft1"><pre><font face='Arial'><b>There</b> <b> are</b> <b> many</b> <b> more</b> <b> features</b> <b> of</b> <b> the</b> <b> Mathematica</b> <b> XML</b> <b> tools,</b> <b> for</b> <b> example,</b> <b> working</b> <b> with</b> <b> attributes,</b> <b> entities,</b></font></pre></span>
<span name = "INTRA" style='top:962px; left:129px' class="ft1"><pre><font face='Arial'><b>namespaces, validation, and CDATA. More information is available from the Mathematica documentation.</b></font></pre></span>
<span name = "INTRA" style='top:1030px; left:129px' class="ft2"><pre><font face='Arial'><b>5.1.3</b> <b>webMathematica XML Applications</b></font></pre></span>
<span name = "INTRA" style='top:1074px; left:129px' class="ft1"><pre><font face='Arial'><b>Many webMathematica applications involve generating HTML to be read by browsers. However, the output from a</b></font></pre></span>
<span name = "INTRA" style='top:1093px; left:129px' class="ft1"><pre><font face='Arial'><b>webMathematica site may not go to a browser; it may involve some data to be read by an application that will then</b></font></pre></span>
<span name = "INTRA" style='top:1111px; left:129px' class="ft1"><pre><font face='Arial'><b>do further processing. This section will study an example that shows how this can be done.</b></font></pre></span>
<span name = "INTRA" style='top:1268px; left:403px' class="ft3"><pre><font face='Arial'> .</font></pre></span>
<span class='nav' style='left: 10px; top: 1010px'><pre><<html>

<head>
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1









Comcast Web Hosting