 Worksheet - Maple Programming Help

Home : Support : Online Help : Connectivity : Web Features : Worksheet Package : Worksheet/FromString

Worksheet

 FromString
 parse a Maple string containing MWS data and convert it to Maple XML tree

 Calling Sequence FromString(str, format=output_format)

Parameters

 str - string; mws or xml string representing Maple worksheet format=output_format - (optional) equation; output_format can be either "maple8_xml" or "mw" (default)

Description

 • The FromString(str) calling sequence parses the input string str, which is assumed to be a valid Maple worksheet. It then converts it to a Maple XML tree.
 • Errors detected by the parser in this routine are reported, but the parser does not validate the worksheet. Only errors that prevent this routine from converting the input string into an internal XML format are detected.
 • FromString maps automatically over its arguments, returning an expression sequence of results.

Examples

The following examples demonstrate how a string can be parsed and converted to a Maple XML tree.

 > $\mathrm{with}\left(\mathrm{Worksheet}\right):$
 > $\mathrm{str}≔"\left\{VERSION 5 0 \"SUN SPARC SOLARIS\" \"5.0\" \right\}\left\{USTYLETAB \right\}\left\{SECT 0 \left\{EXCHG \left\{PARA 0 \"\" 0 \"\" \left\{TEXT -1 21 \"Very simple worksheet\" \right\}\right\}\left\{PARA 0 \"> \" 0 \"\"\left\{MPLTEXT 1 0 16 \"with\left(Worksheet\right);\"\right\}\right\}\right\}\left\{EXCHG \left\{PARA 0 \"> \" 0 \"\" \left\{MPLTEXT 1 0 0 \"\" \right\}\right\}\right\}\right\}\left\{MARK \"1 0 0\" 0 \right\}\left\{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 \right\}\left\{PAGENUMBERS 0 1 2 33 1 1 \right\}"$
 ${\mathrm{str}}{≔}{"\left\{VERSION 5 0 "SUN SPARC SOLARIS" "5.0" \right\}\left\{USTYLETAB \right\}\left\{SECT 0 \left\{EXCHG \left\{PARA 0 "" 0 "" \left\{TEXT -1 21 "Very simple worksheet" \right\}\right\}\left\{PARA 0 "> " 0 ""\left\{MPLTEXT 1 0 16 "with\left(Worksheet\right);"\right\}\right\}\right\}\left\{EXCHG \left\{PARA 0 "> " 0 "" \left\{MPLTEXT 1 0 0 "" \right\}\right\}\right\}\right\}\left\{MARK "1 0 0" 0 \right\}\left\{VIEWOPTS 1 1 0 1 1 1803 1 1 1 1 \right\}\left\{PAGENUMBERS 0 1 2 33 1 1 \right\}"}$ (1)

The string str is parsed and converted to an XML tree data structure doc by using the FromString command.

 > $\mathrm{doc1}≔\mathrm{FromString}\left(\mathrm{str},\mathrm{format}="maple8_xml"\right):$
 > $\mathrm{doc3}≔\mathrm{FromString}\left(\mathrm{str},\mathrm{format}="mw"\right):$

The ToString command converts the XML tree data structure doc and returns it as a Maple string str1.

 > $\mathrm{str1}≔\mathrm{ToString}\left(\mathrm{doc1},\mathrm{format}="mws"\right):$
 > $\mathrm{str2}≔\mathrm{ToString}\left(\mathrm{doc1},\mathrm{format}="maple8_xml"\right):$
 > $\mathrm{str3}≔\mathrm{ToString}\left(\mathrm{doc1},\mathrm{format}="mw"\right):$

The string str1 is once again parsed and converted to an XML tree data structure by using the FromString command.

 > $\mathrm{doc3}≔\mathrm{FromString}\left(\mathrm{str1},\mathrm{format}="maple8_xml"\right):$

The Display command launches the worksheets. The Display command launches the string str1 and the XML tree doc1. For information on Display command parameters, see Worksheet[Display].

 > $\mathrm{Display}\left(\mathrm{str1}\right):$
 > $\mathrm{Display}\left(\mathrm{doc1}\right):$