67
The source for this example is in webMathematica/Examples/XML/Phone.jsp. It also uses an XML file
webMathematica/Examples/XML/phone.xml. If you installed webMathematica as described
above
, you
should be able to connect to this JSP via http://localhost:8080/webMathematica/Examples/XML/Phone.jsp. (You
may have some other URL for accessing your server.)
We first see the XML data.
The contents of Phone.jsp are shown below.
<%@ page language="java" %>
<%@ taglib uri="/webMathematica taglib" prefix="msp" %>
xml = Import[ ToFileName[ MSPPageDirectory[], "phone.xml"],
"XML"] ;
If[ MSPValueQ[ $$name],
patt = "*" <> $$name <> "*";
xml = DeleteCases[xml,
XMLElement[ "Person", {___, "Name"
>n_/;!StringMatchQ[n, patt],___},_ ], Infinity]] ;
MSPReturn[ ExportString[ xml, "XML"], "text/xml"]
This example first imports the XML file into Mathematica. It uses the command MSPPageDirectory because
the XML data is located in the same directory as Phone.jsp. It then checks to see if a parameter name was sent.
If this is the case, then it uses this to discard XML elements that don t match this name. You should be able to see
the operation of this parameter with a URL such as http://localhost:8080/webMathematica/Examples/XML/
Phone.jsp?name=T. (You may have some other URL for accessing your server.)
Of course, you may want to use this XML data for further processing. If you have a system that is XML aware this
is quite straightforward. One useful application that is XML aware is of course Mathematica. For example, the
following will call your webMathematica site and retrieve the information.
In[1]:=
XML Parser XMLGet@"http:eelocalhost:8080ewebMathematicaeExampleseXMLePhone.jsp"D
Out[1]=
XMLObject@DocumentD@
8XMLObject@DeclarationD@Version O 1.0D<, XMLElement@EmployeeList, 8<,
8XMLElement@Person, 8Name O Tom Jones, Email O tomj, Phone O 235 1231<, 8
XMLElement@Person, 8Name O Janet Rogers, Email O jrogers, Phone O 235 1129<, 8
XMLElement@Person,
8Name O Bob Norris, Email O bobn, Phone O 235 1237<, 8
You may even wish to use this in a Mathematica program.
.
<
New Page 1
Comcast Web Hosting