The generate XML command converts an XML Document or XML Element class
into XML text. The resulting XML data may be returned to AppleScript
for further processing or it may be written to a file. XML characters
('<' and '&') are automatically escaped as part
of the XML generation process.
| Parameter |
Type |
Description |
saving as
(new in v2.6) |
file specification |
When specified, the generate XML command writes the resulting XML
data to a file.
CAUTION: Any existing file
will be overwritten without warning. |
generating UTF16
(before v2.6 this parameter was generating unicode) |
boolean |
By default, the generate XML command produces
plain text XML data. When generating UTF16 is true, UTF-16 XML
data is generated. An error is indicated if generating both UTF16
and UTF8 are specified.
NOTE: When generating UTF16 and
generating UTF8 are false, any Unicode characters present in the
XML data structure passed to the
generate
XML command are converted to ? characters. |
generating UTF8
(new in v2.6) |
boolean |
By default, the generate XML command produces
plain text XML data. When generating UTF8 is true, UTF-8 XML data
is generated. An error
is indicated if generating both UTF16 and UTF8 are specified.
NOTE: This option is really
only meaningful when used with the saving as parameter because
AppleScript automatically
converts all UTF-8 unicode strings to UTF-16. |
| including XML declaration |
boolean |
When including XML declaration is true (the default),
the generate XML command includes an XML declaration (e.g. <?xml
... ?>).
The XML version property of the XML document class
may be used to specify the XML version. If the XML version property
is missing, "1.0" is used.
The XML standalone property of the XML document class
controls the standalone attribute of the XML declaration. If the XML
standalone property is missing, the standalone attribute is not included
in the generated XML declaration.
The XML encoding property of the XML document class
controls the encoding attribute of the XML declaration. If the XML
encoding property is missing, the encoding attribute is not generated.
set theXML to {XML standalone:true, XML encoding:¬
"ISO-8859-1", XML version:"1.0", XML tag:"root"}
generate XML theXML with including XML declaration
-- Result:
-- <?xml version="1.0" standalone="yes" encoding="ISO-8859-1"?>
-- <root/>
When including XML declaration is false, only the
root tag is generated:
generate XML theXML without including XML declaration
-- Result: <root/>
|
| including DOCTYPE declaration |
boolean |
When including DOCTYPE declaration is true (the
default), the generate XML command includes a DOCTYPE declaraction
if the XML doctype name, XML doctype publicid or XML doctype systemid
properties of the XML document class are specified.
set theXML to {XML doctype name:"ROOT", XML doctype systemid:"root.dtd", XML tag:"root"}
generate XML theXML with including DOCTYPE declaration
-- Result:
-- <?xml version="1.0"?>
-- <!DOCTYPE ROOT SYSTEM "root.dtd">
-- <root/>
When including DOCTYPE declaration is false, only
the root rag is generated.
generate XML theXML without including DOCTYPE declaration
-- Result: <root/>
|
| including processing instructions |
boolean |
When including processing instructions is true (the
default), any XML processing instruction classes present in the
XML data are
included in the output of the generate
XML command. When including processing instructions is false, XML
processing instruction classes are ignored.
|
| including comments |
boolean |
When including comments is true (the default), any
XML comment classes present in the XML data are included in the
output
of the
generate
XML command. When including comments is false, XML comment classes
are ignored.
|
| pretty printing |
boolean |
When pretty printing is true (the
default), the generate XML command indents nested XML tags and
generates new
lines following any XML
markup making the resulting XML data more readable for humans.
set theData to "<?xml version =\"1.0\"?>
<data>
<xxx att1=\"111\" att2=\"222\">
<yyy>
<zzz>Testing</zzz>
</yyy>
</xxx>
</data>"
set theXML to parse XML theData
set theNewData to generate
XML theXML with pretty
printing
-- Result:
-- <?xml version="1.0"?>
-- <data>
-- <xxx
-- att1="111"
-- att2="222">
-- <yyy>
-- <zzz>
-- Testing
-- </zzz>
-- </yyy>
-- </xxx>
-- </data>
When pretty print is false, little additional whitespace
is introduced, reducing the size of the resulting XML. This is best
for XML intended for consumption by other XML processors.
set theNewData to generate XML theXML without pretty printing
-- Result:
-- <?xml version="1.0"?>
-- <data><xxx att1="111" att2="222"><yyy><zzz>Testing</zzz></yyy></xxx></data>
|