Maple Professional
Maple Academic
Maple Student Edition
Maple Personal Edition
Maple Player
Maple Player for iPad
MapleSim Professional
MapleSim Academic
Maple T.A. - Testing & Assessment
Maple T.A. MAA Placement Test Suite
Möbius - Online Courseware
Machine Design / Industrial Automation
Aerospace
Vehicle Engineering
Robotics
Power Industries
System Simulation and Analysis
Model development for HIL
Plant Modeling for Control Design
Robotics/Motion Control/Mechatronics
Other Application Areas
Mathematics Education
Engineering Education
High Schools & Two-Year Colleges
Testing & Assessment
Students
Financial Modeling
Operations Research
High Performance Computing
Physics
Live Webinars
Recorded Webinars
Upcoming Events
MaplePrimes
Maplesoft Blog
Maplesoft Membership
Maple Ambassador Program
MapleCloud
Technical Whitepapers
E-Mail Newsletters
Maple Books
Math Matters
Application Center
MapleSim Model Gallery
User Case Studies
Exploring Engineering Fundamentals
Teaching Concepts with Maple
Maplesoft Welcome Center
Teacher Resource Center
Student Help Center
Programmatic Worksheet Access
This worksheet demonstrates some of the features of the Worksheet package. This package provides support for accessing Maple worksheets programmatically. As you read this worksheet, execute the commands in sequence.
restart:
Accessing the Worksheet Package
To use the Worksheet package, you must first issue the following call to the procedure with, which provides interactive access to procedures organized in packages.
with(Worksheet);
Importing a Worksheet As an XML Document
Maple worksheets are represented in Maple as XML documents. This makes it unnecessary to know the (undocumented) storage format for the Maple worksheet and allows you to use new and existing tools for manipulating XML document instances. (For details, see XMLTools.) To create an XML representation of a worksheet, use the ReadFile and FromString commands.
wname := cat(kernelopts(datadir), "/../examplesclassic/WorksheetPackage.mws"):
doc := ReadFile(wname):
Converting a Worksheet to Different Formats
Note that Maple worksheets can be imported into Maple in two different formats: -- "mw", this is the same format that is used by the Standard worksheet,
-- "maple8_xml", the format introduced in Maple 8.
Option `format` can be used to specify which XML representation to generate.
doc2 := ReadFile(wname, format = "maple8_xml"):
Display the worksheet you loaded by using the Display command.
# Display(doc);
# Display(doc2);
Use the Convert utility to convert worksheets in "mw" format to worksheets in "maple8_xml" format and back.
doc3 := Convert(doc, format="maple8_xml"):
evalb(doc2 = doc3);
l := XMLTools:-Compare(doc2, doc3);
if l <> [] then [op(l[1..-3], doc2), op(l[1..-3], doc3)] end if;
To convert a worksheet to ".mws" format, use the ToString command.
str := ToString(doc, format = "mws"):
Accessing a Worksheet By Using the XMLTools Package
Now that you have the worksheet exported as an XML document, you can use functions from the XMLTools package to access its subnodes.
XMLTools[FirstChild](doc);
XMLTools[SecondChild](doc);
XMLTools[AttributeTable](%);
XMLTools[ThirdChild](doc);
XMLTools[ElementStatistics](doc);
XMLTools[ContentModelCount](doc);
Return to Index for Example Worksheets
Download Help Document