Close
Close window
Example Worksheet - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Mozilla Firefox.
Maplesoft logo
Maplesoft logo

Online Help

All Products Maple MapleSim


[フレーム] [フレーム]

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 theWorksheet package, you must first issue the following call to the procedurewith ,which provides interactive access to procedures organized in packages.

>

with(Worksheet);

Comparator,Convert,Display,DisplayFile,FromString,ReadFile,ToString,WorksheetToMapleText,WriteFile,worksheet

(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, seeXMLTools .) To create an XML representation of a worksheet, use theReadFile andFromString commands.

>

wname := FileTools:-JoinPath([kernelopts(mapledir), "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 theDisplay command.

>

# Display(doc);

>

# Display(doc2);

Use theConvert utility to convert worksheets in "mw" format to worksheets in "maple8_xml" format and back.

>

doc3 := Convert(doc, format="maple8_xml"):

>

evalb(doc2 = doc3);

false

(3.1)
>

l := XMLTools:-Compare(doc2, doc3);

l:=1,3,1,2,1,2,1

(3.2)
>

if l <> [] then [op(l[1..-3], doc2), op(l[1..-3], doc3)] end if;

_XML_Attribute_XML_AttrNamemajor&comma;_XML_AttrValue6&comma;_XML_Attribute_XML_AttrNamemajor&comma;_XML_AttrValue12

(3.3)

To convert a worksheet to ".mws" format, use theToString 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);

_XML_Text

(4.1)
>

XMLTools[SecondChild](doc);

_XML_Element_XML_ElementTypeVersion&comma;_XML_Attribute_XML_AttrNamemajor&comma;_XML_AttrValue12&comma;_XML_Attribute_XML_AttrNameminor&comma;_XML_AttrValue0&comma;

(4.2)
>

XMLTools[AttributeTable](%);

tablemajor&equals;12&comma;minor&equals;0

(4.3)
>

XMLTools[ThirdChild](doc);

_XML_Text

(4.4)
>

XMLTools[ElementStatistics](doc);

View-Properties&equals;1&comma;Label-Scheme&equals;1&comma;Version&equals;1&comma;Task&equals;1&comma;Styles&equals;1&comma;Worksheet&equals;3&comma;Section&equals;4&comma;Title&equals;6&comma;Equation&equals;10&comma;Output&equals;10&comma;Hyperlink&equals;21&comma;Layout&equals;24&comma;Input&equals;26&comma;Group&equals;26&comma;Text-field&equals;45&comma;Font&equals;112

(4.5)
>

XMLTools[ContentModelCount](doc);

27

(4.6)

Return to Index for Example Worksheets


Download Help Document

AltStyle によって変換されたページ (->オリジナル) /