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.
|
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.
| (1.1) |
|
|
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.
Use the Convert
utility to convert worksheets in "mw" format to worksheets in "maple8_xml" format and back.
>
|
doc3 := Convert(doc, format="maple8_xml"):
|
| (3.1) |
>
|
l := XMLTools:-Compare(doc2, doc3);
|
| (3.2) |
>
|
if l <> [] then [op(l[1..-3], doc2), op(l[1..-3], doc3)] end if;
|
| (3.3) |
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);
|
| (4.1) |
>
|
XMLTools[SecondChild](doc);
|
| (4.2) |
>
|
XMLTools[AttributeTable](%);
|
| (4.3) |
>
|
XMLTools[ThirdChild](doc);
|
| (4.4) |
>
|
XMLTools[ElementStatistics](doc);
|
| (4.5) |
>
|
XMLTools[ContentModelCount](doc);
|
| (4.6) |
|
Return to Index for Example Worksheets
|
Download Help Document
Was this information helpful?