- Hello world! written in MetaL
Source code of the Hello world! program written in MetaL.
<?xml version="1.0"?>
<!--
@(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
-->
<output>
<script>
<string>Hello World! </string>
</script>
</output>
|
- Hello world! generated in PHP
Source code of the Hello world! program generated in PHP by the MetaL compiler.
<?php
echo "Hello World!\n";
?>
|
- Hello world! generated in Java
Source code of the Hello world! program generated in Java by the MetaL compiler.
public final class helloworld
{
public static void main(String[] args)
{
System.out.print("Hello World!\n");
}
}
|
- MetaL source code of a real example of a OOP class
Example of the definition of one real object oriented programming class written in Metal for generating XML documents.
<class>
<documentation>
<idiom>en</idiom>
<purpose>Composing and generating XML documents.</purpose>
<usage>The class has several independent functions that should be used
to compose the structure of an XML document. When the structure is
fully composed, the <functionlink>write</functionlink> should be used
to output the document in the XML format.</usage>
<example>Here follows an example of typical use of this class:<pre><examplecode>
<comment>First create an object of the class.</comment>
<set> <xmlwriterobject /> <createxmlwriterobject /> </set>
<comment>Now, start defining the XML document from the root tag.</comment>
<set> <hashvariable>noattributes</hashvariable> <hash /> </set>
<void><addxmlwritertag>
<arguments>
<tag><string>myxmldocument</string></tag>
<attributes><variable>noattributes</variable></attributes>
<parent><emptystring /></parent>
<path><variable>root</variable></path>
<indent><true /></indent>
</arguments>
</addxmlwritertag></void>
<comment>Then define the rest of the document tags and data.</comment>
<void><addxmlwritertag>
<arguments>
<tag><string>name</string></tag>
<attributes><variable>noattributes</variable></attributes>
<parent><buffervalue><variable>root</variable></buffervalue></parent>
<path><variable>toptag</variable></path>
<indent><false /></indent>
</arguments>
</addxmlwritertag></void>
<void><addxmlwriterdata>
<arguments>
<data><string>John Doe</string></data>
<parent><buffervalue><variable>toptag</variable></buffervalue></parent>
<path><variable>path</variable></path>
</arguments>
</addxmlwriterdata></void>
<comment>Tags may have attributes.</comment>
<set> <hashvariable>attributes</hashvariable> <hash /> </set>
<setentry>
<hashvariable>attributes</hashvariable>
<string>country</string>
<string>us</string>
</setentry>
<void><addxmlwritertag>
<arguments>
<tag><string>address</string></tag>
<attributes><variable>attributes</variable></attributes>
<parent><buffervalue><variable>root</variable></buffervalue></parent>
<path><variable>toptag</variable></path>
<indent><true /></indent>
</arguments>
</addxmlwritertag></void>
<comment>Tags and the correspondent data may be added with a single function call.</comment>
<void><addxmlwriterdatatag>
<arguments>
<tag><string>street</string></tag>
<attributes><variable>noattributes</variable></attributes>
<parent><buffervalue><variable>toptag</variable></buffervalue></parent>
<path><variable>datatag</variable></path>
<data><string>Wall Street, 1641</string></data>
</arguments>
</addxmlwriterdatatag></void>
<void><addxmlwriterdatatag>
<arguments>
<tag><string>zip</string></tag>
<attributes><variable>noattributes</variable></attributes>
<parent><buffervalue><variable>toptag</variable></buffervalue></parent>
<path><variable>datatag</variable></path>
<data><string>NY 72834</string></data>
</arguments>
</addxmlwriterdatatag></void>
<comment>Any time before generating the document you may specify a DTD to let other tools validate it...</comment>
<set>
<xmlwriterobjectvariable>dtdtype</xmlwriterobjectvariable>
<string>SYSTEM</string>
</set>
<set>
<xmlwriterobjectvariable>dtdurl</xmlwriterobjectvariable>
<string>myxmldocument.dtd</string>
</set>
<comment>...and a stylesheet for displaying the document in particular way in XML capable browsers.</comment>
<set>
<xmlwriterobjectvariable>stylesheettype</xmlwriterobjectvariable>
<string>text/xsl</string>
</set>
<set>
<xmlwriterobjectvariable>stylesheet</xmlwriterobjectvariable>
<string>myxmldocument.xsl</string>
</set>
<comment>When you are done with the XML document definition, generate it.</comment>
<if>
<istrue>
<writexml>
<arguments>
<output><variable>output</variable></output>
</arguments>
</writexml>
</istrue>
<then>
<comment>If the document was generated successfully, you may not output it.</comment>
<buffervalue><variable>output</variable></buffervalue>
</then>
<else>
<comment>If there was an error, output it as well.</comment>
<group><string>Error: </string><join /><xmlwriterobjectvariable>error</xmlwriterobjectvariable></group>
</else>
</if>
</examplecode></pre></example>
</documentation>
<file><installpath />/library/xml/xml_writer_class<languageextension /></file>
<basepath><openpath /></basepath>
<tag>METAL_LIBRARY_XML_XML_WRITER_CLASS</tag>
<version>@(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $</version>
<copyright>Copyright © (C) Manuel Lemos 2001-2002</copyright>
<title>XML writer</title>
<author>Manuel Lemos</author>
<authoraddress>mlemos@acm.org</authoraddress>
<variable>
<name>structure</name>
<type>HASH</type>
<value></value>
<protected />
</variable>
<variable>
<name>nodes</name>
<type>HASH</type>
<value></value>
<protected />
</variable>
<variable>
<name>stylesheet</name>
<type>STRING</type>
<value></value>
<documentation>
<idiom>en</idiom>
<purpose>Define the URL for the default stylesheet definition to be
used render the XML document.</purpose>
<usage>If you intend that browsers display this document in specific
way define the URL of where it is located the stylesheet to be used
to render the document. Set this variable to an empty string if you
do not intend to specify a stylesheet.</usage>
</documentation>
</variable>
<variable>
<name>stylesheettype</name>
<type>STRING</type>
<value>text/xsl</value>
<documentation>
<idiom>en</idiom>
<purpose>Stylesheets may be of several types. This variable defines
the MIME content type of the stylesheet specified for this document.</purpose>
<usage>Set this variable to MIME designation for the type of
stylesheet defined by the variable
<variablelink>stylesheet</variablelink>.</usage>
<example><tt><stringvalue>text/css</stringvalue></tt></example>
</documentation>
</variable>
<variable>
<name>dtdtype</name>
<type>STRING</type>
<value></value>
<documentation>
<idiom>en</idiom>
<purpose>Define which type of document type definition (DTD).</purpose>
<usage>If you intend to specify a DTD, eventually for validation
purposes, set this variable to either:
<stringvalue>INTERNAL</stringvalue>,
<stringvalue>SYSTEM</stringvalue> or
<stringvalue>PUBLIC</stringvalue>. Set this variable to an empty
string to not use a DTD. <stringvalue>INTERNAL</stringvalue> mean
that the DTD is bein defined inline within the
<variablelink>dtddefinition</variablelink> variable.
<stringvalue>SYSTEM</stringvalue> or
<stringvalue>PUBLIC</stringvalue> means that the DTD is defined in
an external resource defined by either
<variablelink>dtddefinition</variablelink> or
<variablelink>dtdurl</variablelink>.</usage>
</documentation>
</variable>
<variable>
<name>dtddefinition</name>
<type>STRING</type>
<value></value>
<documentation>
<idiom>en</idiom>
<purpose>Define of the DTD.</purpose>
<usage>For an internal DTD, this variable should contain the actual
DTD definition. For an external DTD, it should be of the form
<tt><stringvalue>Registration//Organization//Type Label//Definition Language</stringvalue></tt>.</usage>
<example>Example of an internal DTD definition:<pbr />
<tt><stringvalue><!ELEMENT html (head, body)> <!ELEMENT head (title?)> <!ELEMENT title (#PCDATA)> <!ELEMENT body (#PCDATA)> </stringvalue></tt><pbr />
Example of an external DTD definition:<pbr />
<tt><stringvalue>-//W3C//DTD XHTML 1.0 Strict//EN</stringvalue></tt></example>
</documentation>
</variable>
<variable>
<name>dtdurl</name>
<type>STRING</type>
<value></value>
<documentation>
<idiom>en</idiom>
<purpose>Define the URL of an external DTD.</purpose>
<usage>Optionally specify an absolute or relative URL of an external
DTD.</usage>
<example><tt><stringvalue>http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd</stringvalue></tt></example>
</documentation>
</variable>
<variable>
<name>outputencoding</name>
<type>STRING</type>
<value>utf-8</value>
<documentation>
<idiom>en</idiom>
<purpose>Define the character set encoding of the output
document.</purpose>
<usage>Currently the class supports only the encodings <tt>utf-8</tt>
or <tt>iso-8859-1</tt>.</usage>
</documentation>
</variable>
<variable>
<name>inputencoding</name>
<type>STRING</type>
<value>iso-8859-1</value>
<documentation>
<idiom>en</idiom>
<purpose>Define the character set encoding of the of the data values
passed to the function <functionlink>adddata</functionlink> or the
attribute values passed to the function
<functionlink>addtag</functionlink>.</purpose>
<usage>Currently the class supports only the encodings <tt>utf-8</tt>
or <tt>iso-8859-1</tt>.</usage>
</documentation>
</variable>
<variable>
<name>linebreak</name>
<type>STRING</type>
<value> </value>
<documentation>
<idiom>en</idiom>
<purpose>Characters to be used when breaking lines of the output XML
document.</purpose>
<usage>Use either <stringvalue> </stringvalue>,
<stringvalue> </stringvalue> or
<stringvalue> </stringvalue>.</usage>
</documentation>
</variable>
<variable>
<name>indenttext</name>
<type>STRING</type>
<value> </value>
<documentation>
<idiom>en</idiom>
<purpose>Characters to be used when indenting the lines of the output
XML document.</purpose>
<usage>Use either one or more spaces or tab characters.</usage>
</documentation>
</variable>
<variable>
<name>error</name>
<type>STRING</type>
<value></value>
<documentation>
<idiom>en</idiom>
<purpose>Contains the error message that explains the reason of
failure of certain class functions.</purpose>
<usage>Check this variable when a given class function fails.</usage>
</documentation>
</variable>
<function>
<name>escapedata</name>
<type>STRING</type>
<protected />
<argument>
<name>data</name>
<type>STRING</type>
</argument>
<do>
<set> <variable>position</variable> <zero /> </set>
<set> <variable>length</variable> <length><argument>data</argument></length> </set>
<set> <variable>escapeddata</variable> <emptystring /> </set>
<loop>
<while>
<variable>position</variable> <less /> <variable>length</variable>
</while>
<do>
<set>
<variable>character</variable>
<substring>
<argument>data</argument>
<variable>position</variable>
<one />
</substring>
</set>
<set>
<variable>code</variable>
<code><variable>character</variable></code>
</set>
<switch>
<value><integervariable>code</integervariable></value>
<case>
<value>34</value>
<do>
<set>
<variable>character</variable>
<string>&quot;</string>
</set>
<break />
</do>
</case>
<case>
<value>38</value>
<do>
<set>
<variable>character</variable>
<string>&amp;</string>
</set>
<break />
</do>
</case>
<case>
<value>39</value>
<do>
<set>
<variable>character</variable>
<string>&apos;</string>
</set>
<break />
</do>
</case>
<case>
<value>60</value>
<do>
<set>
<variable>character</variable>
<string>&lt;</string>
</set>
<break />
</do>
</case>
<case>
<value>62</value>
<do>
<set>
<variable>character</variable>
<string>&gt;</string>
</set>
<break />
</do>
</case>
<default>
<do>
<if>
<istrue>
<variable>code</variable> <less /> <integer>32</integer>
</istrue>
<then>
<set>
<variable>character</variable>
<group>
<string>&#</string>
<join />
<converttostring><variable>code</variable></converttostring>
<join />
<string>;</string>
</group>
</set>
</then>
</if>
<break />
</do>
</default>
</switch>
<concatenate>
<string><variable>escapeddata</variable></string>
<append><variable>character</variable></append>
</concatenate>
<increment><variable>position</variable></increment>
</do>
</loop>
<return><variable>escapeddata</variable></return>
</do>
</function>
<function>
<name>encodedata</name>
<type>BOOLEAN</type>
<protected />
<documentation>
<idiom>en</idiom>
<purpose>Encodes text in a suitable form for outputting as XML data
parts or tag attributes.</purpose>
<usage>Pass text data in the encoding type defined by the
<variablelink>inputencoding</variablelink> variable and expect the
encoded result in the encoding type defined by the
<variablelink>outputencoding</variablelink> variable.</usage>
<returnvalue>Success boolean flag. If this flag is
<tt><booleanvalue>0</booleanvalue></tt> then the
<variablelink>error</variablelink> variable contains the error
message that explains the failure.</returnvalue>
</documentation>
<argument>
<name>data</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Input text data in the encoding type defined by the
<variablelink>inputencoding</variablelink> variable.</purpose>
</documentation>
</argument>
<argument>
<name>encodeddata</name>
<type>STRING</type>
<out />
<documentation>
<idiom>en</idiom>
<purpose>Encoded result data in the encoding type defined by the
<variablelink>outputencoding</variablelink> variable.</purpose>
</documentation>
</argument>
<do>
<if>
<istrue>
<this>inputencoding</this> <equalstrings /> <this>outputencoding</this>
</istrue>
<then>
<setbuffer>
<argument>encodeddata</argument>
<callthis>
<function>escapedata</function>
<arguments>
<data><argument>data</argument></data>
</arguments>
</callthis>
</setbuffer>
</then>
<else>
<switch>
<value><lowercase><this>outputencoding</this></lowercase></value>
<case>
<value>utf-8</value>
<do>
<if>
<istrue>
<lowercase><this>inputencoding</this></lowercase> <equalstrings /> <string>iso-8859-1</string>
</istrue>
<then>
<utf8encode>
<data><callthis>
<function>escapedata</function>
<arguments>
<data><argument>data</argument></data>
</arguments>
</callthis></data>
<encoded><stringvariable>encoded_data</stringvariable></encoded>
</utf8encode>
<setbuffer>
<argument>encodeddata</argument>
<variable>encoded_data</variable>
</setbuffer>
</then>
<else>
<set>
<this>error</this>
<group>
<string>can not encode iso-8859-1 data in </string>
<join />
<this>outputencoding</this>
</group>
</set>
<return><false /></return>
</else>
</if>
<break />
</do>
</case>
<case>
<value>iso-8859-1</value>
<do>
<if>
<istrue>
<lowercase><this>inputencoding</this></lowercase> <equalstrings /> <string>utf-8</string>
</istrue>
<then>
<utf8decode>
<decoded><stringvariable>decoded</stringvariable></decoded>
<data><argument>data</argument></data>
</utf8decode>
<setbuffer>
<argument>encodeddata</argument>
<callthis>
<function>escapedata</function>
<arguments>
<data><variable>decoded</variable></data>
</arguments>
</callthis>
</setbuffer>
</then>
<else>
<set>
<this>error</this>
<group>
<string>can not encode utf-8 data in </string>
<join />
<this>outputencoding</this>
</group>
</set>
<return><false /></return>
</else>
</if>
<break />
</do>
</case>
<default>
<do>
<set>
<this>error</this>
<group>
<string>can not encode data in </string>
<join />
<this>inputencoding</this>
</group>
</set>
<return><false /></return>
</do>
</default>
</switch>
</else>
</if>
<return><true /></return>
</do>
</function>
<function>
<name>writetag</name>
<type>BOOLEAN</type>
<protected />
<argument>
<name>output</name>
<type>STRING</type>
<inout />
</argument>
<argument>
<name>path</name>
<type>STRING</type>
</argument>
<argument>
<name>indent</name>
<type>STRING</type>
</argument>
<do>
<set>
<variable>tag</variable>
<stringentry>
<hashentry>
<this>structure</this>
<argument>path</argument>
</hashentry>
<string>Tag</string>
</stringentry>
</set>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string><</string>
<join />
<variable>tag</variable>
</group></append>
</concatenate>
<set>
<variable>attributecount</variable>
<count><hashentry>
<hashentry>
<this>structure</this>
<argument>path</argument>
</hashentry>
<string>Attributes</string>
</hashentry></count>
</set>
<if>
<istrue>
<variable>attributecount</variable> <more /> <zero />
</istrue>
<then>
<set>
<variable>attributes</variable>
<hashentry>
<hashentry>
<this>structure</this>
<argument>path</argument>
</hashentry>
<string>Attributes</string>
</hashentry>
</set>
<reset>
<hash><variable>attributes</variable></hash>
<cursor>cursor</cursor>
<key><stringvariable>key</stringvariable></key>
<end><booleanvariable>end</booleanvariable></end>
</reset>
<loop>
<while>
<not><variable>end</variable></not>
</while>
<do>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string> </string>
<join />
<variable>key</variable>
<join />
<string>="</string>
<join />
<stringentry>
<hashvariable>attributes</hashvariable>
<variable>key</variable>
</stringentry>
<join />
<string>"</string>
</group></append>
</concatenate>
<next>
<hash><variable>attributes</variable></hash>
<cursor>cursor</cursor>
<key><variable>key</variable></key>
<end><variable>end</variable></end>
</next>
</do>
</loop>
</then>
</if>
<set>
<variable>elements</variable>
<integerentry>
<hashentry>
<this>structure</this>
<argument>path</argument>
</hashentry>
<string>Elements</string>
</integerentry>
</set>
<if>
<istrue>
<variable>elements</variable> <more /> <zero />
</istrue>
<then>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><string>></string></append>
</concatenate>
<set>
<variable>doindent</variable>
<booleanentry>
<hashentry>
<this>structure</this>
<argument>path</argument>
</hashentry>
<string>Indent</string>
</booleanentry>
</set>
<set>
<variable>elementindent</variable>
<conditional>
<istrue>
<variable>doindent</variable>
</istrue>
<then>
<this>linebreak</this>
<join />
<argument>indent</argument>
<join />
<this>indenttext</this>
</then>
<else>
<emptystring />
</else>
</conditional>
</set>
<set>
<variable>element</variable>
<zero />
</set>
<loop>
<while>
<variable>element</variable> <less /> <variable>elements</variable>
</while>
<do>
<set>
<variable>elementpath</variable>
<group>
<argument>path</argument>
<join />
<string>,</string>
<join />
<converttostring><variable>element</variable></converttostring>
</group>
</set>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><variable>elementindent</variable></append>
</concatenate>
<if>
<istrue>
<entrydefined>
<this>nodes</this>
<variable>elementpath</variable>
</entrydefined>
</istrue>
<then>
<if>
<isfalse>
<callthis>
<function>writetag</function>
<arguments>
<output><argument>output</argument></output>
<path><variable>elementpath</variable></path>
<indent><argument>indent</argument><join /><this>indenttext</this></indent>
</arguments>
</callthis>
</isfalse>
<then>
<return><false /></return>
</then>
</if>
</then>
<else>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><stringentry>
<this>structure</this>
<stringvariable>elementpath</stringvariable>
</stringentry></append>
</concatenate>
</else>
</if>
<increment><variable>element</variable></increment>
</do>
</loop>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<conditional>
<istrue>
<variable>doindent</variable>
</istrue>
<then>
<this>linebreak</this>
<join />
<argument>indent</argument>
</then>
<else>
<emptystring />
</else>
</conditional>
<join />
<string></</string>
<join />
<variable>tag</variable>
<join />
<string>></string>
</group></append>
</concatenate>
</then>
<else>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><string>/></string></append>
</concatenate>
</else>
</if>
<return><true /></return>
</do>
</function>
<function>
<name>write</name>
<type>BOOLEAN</type>
<documentation>
<idiom>en</idiom>
<purpose>Generate the XML document.</purpose>
<usage>Pass a reference to a string variable that will hold the
resulting XML document.</usage>
<returnvalue>Success boolean flag. If this flag is
<tt><booleanvalue>0</booleanvalue></tt> then the
<variablelink>error</variablelink> variable contains the error
message that explains the failure.</returnvalue>
</documentation>
<argument>
<name>output</name>
<type>STRING</type>
<out />
<documentation>
<idiom>en</idiom>
<purpose>Reference to a variable that will hold the resulting XML
document.</purpose>
</documentation>
</argument>
<do>
<if>
<istrue>
<this>error</this> <differentstrings /> <emptystring />
</istrue>
<then>
<return><false /></return>
</then>
</if>
<if>
<isfalse>
<entrydefined>
<this>structure</this>
<string>0</string>
</entrydefined>
</isfalse>
<then>
<set>
<this>error</this>
<string>XML document structure is empty</string>
</set>
<return><false /></return>
</then>
</if>
<setbuffer>
<argument>output</argument>
<group>
<string><?xml version="1.0" encoding="</string>
<join />
<this>outputencoding</this>
<join />
<string>"?></string>
<join />
<this>linebreak</this>
</group>
</setbuffer>
<if>
<istrue>
<this>dtdtype</this> <differentstrings /> <emptystring />
</istrue>
<then>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string><!DOCTYPE </string>
<join />
<stringentry>
<hashentry>
<this>structure</this>
<string>0</string>
</hashentry>
<string>Tag</string>
</stringentry>
<join />
<string> </string>
</group></append>
</concatenate>
<switch>
<value><this>dtdtype</this></value>
<case>
<value>INTERNAL</value>
<do>
<if>
<istrue>
<this>dtddefinition</this> <equalstrings /> <emptystring />
</istrue>
<then>
<set>
<this>error</this>
<string>it was not specified a valid internal DTD definition</string>
</set>
<return><false /></return>
</then>
</if>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string>[</string>
<join />
<this>linebreak</this>
<join />
<this>dtddefinition</this>
<join />
<this>linebreak</this>
<join />
<string>]</string>
</group></append>
</concatenate>
<break />
</do>
</case>
<case>
<value>SYSTEM</value>
<do>
<if>
<istrue>
<this>dtdurl</this> <equalstrings /> <emptystring />
</istrue>
<then>
<set>
<this>error</this>
<string>it was not specified a valid system DTD url</string>
</set>
<return><false /></return>
</then>
</if>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><string>SYSTEM</string></append>
</concatenate>
<if>
<istrue>
<this>dtddefinition</this> <differentstrings /> <emptystring />
</istrue>
<then>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string> "</string>
<join />
<this>dtddefinition</this>
<join />
<string>"</string>
</group></append>
</concatenate>
</then>
</if>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string> "</string>
<join />
<this>dtdurl</this>
<join />
<string>"</string>
</group></append>
</concatenate>
<break />
</do>
</case>
<case>
<value>PUBLIC</value>
<do>
<if>
<istrue>
<this>dtddefinition</this> <equalstrings /> <emptystring />
</istrue>
<then>
<set>
<this>error</this>
<string>it was not specified a valid public DTD definition</string>
</set>
<return><false /></return>
</then>
</if>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string>PUBLIC "</string>
<join />
<this>dtddefinition</this>
<join />
<string>"</string>
</group></append>
</concatenate>
<if>
<istrue>
<this>dtdurl</this> <differentstrings /> <emptystring />
</istrue>
<then>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string> "</string>
<join />
<this>dtdurl</this>
<join />
<string>"</string>
</group></append>
</concatenate>
</then>
</if>
<break />
</do>
</case>
<default>
<do>
<set>
<this>error</this>
<string>it was not specified a valid DTD type</string>
</set>
<return><false /></return>
</do>
</default>
</switch>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string>></string>
<join />
<this>linebreak</this>
</group></append>
</concatenate>
</then>
</if>
<if>
<istrue>
<this>stylesheet</this> <differentstrings /> <emptystring />
</istrue>
<then>
<if>
<istrue>
<this>stylesheettype</this> <equalstrings /> <emptystring />
</istrue>
<then>
<set>
<this>error</this>
<string>it was not specified a valid stylesheet type</string>
</set>
<return><false /></return>
</then>
</if>
<concatenate>
<buffer><argument>output</argument></buffer>
<append><group>
<string><?xml-stylesheet type="</string>
<join />
<this>stylesheettype</this>
<join />
<string>" href="</string>
<join />
<this>stylesheet</this>
<join />
<string>"?></string>
<join />
<this>linebreak</this>
</group></append>
</concatenate>
</then>
</if>
<return><callthis>
<function>writetag</function>
<arguments>
<output><argument>output</argument></output>
<path><string>0</string></path>
<indent><emptystring /></indent>
</arguments>
</callthis></return>
</do>
</function>
<function>
<name>addtag</name>
<type>BOOLEAN</type>
<documentation>
<idiom>en</idiom>
<purpose>Add a tag to the XML document structure.</purpose>
<usage>Specify the tag definition and the parent XML document element
where the tag will be added.</usage>
<returnvalue>Success boolean flag. If this flag is
<tt><booleanvalue>0</booleanvalue></tt> then the
<variablelink>error</variablelink> variable contains the error
message that explains the failure. This return value may be
safely ignored if the function call arguments are correctly
defined.</returnvalue>
</documentation>
<argument>
<name>tag</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Name of the tag to be added.</purpose>
</documentation>
</argument>
<argument>
<name>attributes</name>
<type>HASH</type>
<defaultvalue></defaultvalue>
<documentation>
<idiom>en</idiom>
<purpose>Associative array that defines the list of attributes of
the tag, if any. The indexes of the array entries are the names of
the attributes and the values array entries are the attribute
values defined in encoding type specified by the
<variablelink>inputencoding</variablelink> variable.</purpose>
</documentation>
</argument>
<argument>
<name>parent</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Path of the parent XML document tag element within each
which the new tag is being added. If the new tag is the document
root tag, the parent path is <tt><stringvalue></stringvalue></tt>.
The path of previously added tags is returned by the <argumentlink>
<function>addtag</function>
<argument>path</argument>
</argumentlink> argument of previous calls to this
function.</purpose>
</documentation>
</argument>
<argument>
<name>path</name>
<type>STRING</type>
<out />
<documentation>
<idiom>en</idiom>
<purpose>Reference to a variable that will hold the path of the
XML document tag element that is added by this function.</purpose>
</documentation>
</argument>
<argument>
<name>indent</name>
<type>BOOLEAN</type>
<documentation>
<idiom>en</idiom>
<purpose>Flag that determines if the elements to be added within
this tag will be outputted in individual indented lines.</purpose>
</documentation>
</argument>
<do>
<if>
<istrue>
<this>error</this> <differentstrings /> <emptystring />
</istrue>
<then>
<return><false /></return>
</then>
</if>
<setbuffer>
<argument>path</argument>
<conditional>
<istrue>
<argument>parent</argument> <equalstrings /> <emptystring />
</istrue>
<then>
<string>0</string>
</then>
<else>
<group>
<argument>parent</argument>
<join />
<string>,</string>
<join />
<converttostring><integerentry>
<hashentry>
<this>structure</this>
<argument>parent</argument>
</hashentry>
<string>Elements</string>
</integerentry></converttostring>
</group>
</else>
</conditional>
</setbuffer>
<if>
<istrue>
<entrydefined>
<this>structure</this>
<buffervalue><argument>path</argument></buffervalue>
</entrydefined>
</istrue>
<then>
<set>
<this>error</this>
<group>
<string>tag with path </string>
<join />
<buffervalue><argument>path</argument></buffervalue>
<join />
<string> is already defined</string>
</group>
</set>
<return><false /></return>
</then>
</if>
<set> <variable>encodedattributes</variable> <hash /> </set>
<reset>
<hash><argument>attributes</argument></hash>
<cursor>cursor</cursor>
<key><stringvariable>attribute_name</stringvariable></key>
<end><booleanvariable>end</booleanvariable></end>
</reset>
<loop>
<while>
<not><variable>end</variable></not>
</while>
<do>
<setentry>
<hashvariable>encodedattributes</hashvariable>
<variable>attribute_name</variable>
<emptystring />
</setentry>
<if>
<isfalse>
<callthis>
<function>encodedata</function>
<arguments>
<data><stringentry>
<argument>attributes</argument>
<variable>attribute_name</variable>
</stringentry></data>
<encodeddata><variable>encoded_data</variable></encodeddata>
</arguments>
</callthis>
</isfalse>
<then>
<return><false /></return>
</then>
</if>
<setentry>
<hashvariable>encodedattributes</hashvariable>
<variable>attribute_name</variable>
<buffervalue><variable>encoded_data</variable></buffervalue>
</setentry>
<next>
<hash><argument>attributes</argument></hash>
<cursor>cursor</cursor>
<key><variable>attribute_name</variable></key>
<end><variable>end</variable></end>
</next>
</do>
</loop>
<hashreset>
<hash><this>structure</this></hash>
<index><buffervalue><argument>path</argument></buffervalue></index>
<values>
<string>Tag</string> <argument>tag</argument>
<string>Attributes</string> <variable>encodedattributes</variable>
<string>Elements</string> <zero />
<string>Indent</string> <argument>indent</argument>
</values>
</hashreset>
<setentry>
<this>nodes</this>
<buffervalue><argument>path</argument></buffervalue>
<true />
</setentry>
<if>
<istrue>
<argument>parent</argument> <differentstrings /> <emptystring />
</istrue>
<then>
<setentry>
<hashentryindex>
<this>structure</this>
<argument>parent</argument>
</hashentryindex>
<string>Elements</string>
<group>
<integerentry>
<hashentry>
<this>structure</this>
<argument>parent</argument>
</hashentry>
<string>Elements</string>
</integerentry>
<plus />
<one />
</group>
</setentry>
</then>
</if>
<return><true /></return>
</do>
</function>
<function>
<name>adddata</name>
<type>BOOLEAN</type>
<documentation>
<idiom>en</idiom>
<purpose>Add a data part to the XML document structure.</purpose>
<usage>Specify the data text and the parent XML document element
where the tag will be added.</usage>
<returnvalue>Success boolean flag. If this flag is
<tt><booleanvalue>0</booleanvalue></tt> then the
<variablelink>error</variablelink> variable contains the error
message that explains the failure. This return value may be
safely ignored if the function call arguments are correctly
defined.</returnvalue>
</documentation>
<argument>
<name>data</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Data text to be added.</purpose>
</documentation>
</argument>
<argument>
<name>parent</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Path of the parent XML document tag element within each
which the new data part is being added. The path of previously
added tags is returned by the <argumentlink>
<function>addtag</function>
<argument>path</argument>
</argumentlink> argument of previous calls to the
<functionlink>addtag</functionlink> function.</purpose>
</documentation>
</argument>
<argument>
<name>path</name>
<type>STRING</type>
<out />
<documentation>
<idiom>en</idiom>
<purpose>Reference to a variable that will hold the path of the
XML document data part element that is added by this
function.</purpose>
</documentation>
</argument>
<do>
<if>
<istrue>
<this>error</this> <differentstrings /> <emptystring />
</istrue>
<then>
<return><false /></return>
</then>
</if>
<if>
<isfalse>
<entrydefined>
<this>structure</this>
<argument>parent</argument>
</entrydefined>
</isfalse>
<then>
<set>
<this>error</this>
<group>
<string>the parent tag path</string>
<join />
<buffervalue><argument>path</argument></buffervalue>
<join />
<string>is not defined</string>
</group>
</set>
<return><false /></return>
</then>
</if>
<if>
<istrue>
<argument>data</argument> <equalstrings /> <emptystring />
</istrue>
<then>
<return><true /></return>
</then>
</if>
<setbuffer>
<argument>path</argument>
<group>
<argument>parent</argument>
<join />
<string>,</string>
<join />
<converttostring><integerentry>
<hashentry>
<this>structure</this>
<argument>parent</argument>
</hashentry>
<string>Elements</string>
</integerentry></converttostring>
</group>
</setbuffer>
<if>
<isfalse>
<callthis>
<function>encodedata</function>
<arguments>
<data><argument>data</argument></data>
<encodeddata><variable>encoded_data</variable></encodeddata>
</arguments>
</callthis>
</isfalse>
<then>
<return><false /></return>
</then>
</if>
<setentry>
<this>structure</this>
<buffervalue><argument>path</argument></buffervalue>
<buffervalue><variable>encoded_data</variable></buffervalue>
</setentry>
<setentry>
<hashentryindex>
<this>structure</this>
<argument>parent</argument>
</hashentryindex>
<string>Elements</string>
<group>
<integerentry>
<hashentry>
<this>structure</this>
<argument>parent</argument>
</hashentry>
<string>Elements</string>
</integerentry>
<plus />
<one />
</group>
</setentry>
<return><true /></return>
</do>
</function>
<function>
<name>adddatatag</name>
<type>BOOLEAN</type>
<documentation>
<idiom>en</idiom>
<purpose>Add a tag with data to the XML document structure.</purpose>
<usage>Specify the tag definition, the text data and the parent XML
document element where the tag will be added.</usage>
<returnvalue>Success boolean flag. If this flag is
<tt><booleanvalue>0</booleanvalue></tt> then the
<variablelink>error</variablelink> variable contains the error
message that explains the failure. This return value may be safely
ignored if the function call arguments are correctly defined.</returnvalue>
</documentation>
<argument>
<name>tag</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Name of the tag to be added.</purpose>
</documentation>
</argument>
<argument>
<name>attributes</name>
<type>HASH</type>
<defaultvalue></defaultvalue>
<documentation>
<idiom>en</idiom>
<purpose>Associative array that defines the list of attributes of
the tag, if any. The indexes of the array entries are the names of
the attributes and the values array entries are the attribute
values defined in encoding type specified by the
<variablelink>inputencoding</variablelink> variable.</purpose>
</documentation>
</argument>
<argument>
<name>data</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Data text to be added.</purpose>
</documentation>
</argument>
<argument>
<name>parent</name>
<type>STRING</type>
<documentation>
<idiom>en</idiom>
<purpose>Path of the parent XML document tag element within each
which the new tag is being added. The path of previously added
tags is returned by the <argumentlink>
<function>addtag</function>
<argument>path</argument>
</argumentlink> argument of previous
calls to the <functionlink>addtag</functionlink> function.</purpose>
</documentation>
</argument>
<argument>
<name>path</name>
<type>STRING</type>
<out />
<documentation>
<idiom>en</idiom>
<purpose>Reference to a variable that will hold the path of the
XML document tag element that is added by this function.</purpose>
</documentation>
</argument>
<do>
<return>
<callthis>
<function>addtag</function>
<arguments>
<tag><argument>tag</argument></tag>
<attributes><argument>attributes</argument></attributes>
<parent><argument>parent</argument></parent>
<path><argument>path</argument></path>
<indent><false /></indent>
</arguments>
</callthis>
<and />
<callthis>
<function>adddata</function>
<arguments>
<data><argument>data</argument></data>
<parent><buffervalue><argument>path</argument></buffervalue></parent>
<path><variable>datapath</variable></path>
</arguments>
</callthis>
</return>
</do>
</function>
</class>
|
- PHP class generated from MetaL source code
Example of the PHP code generated from the MetaL source code above.
<?php
if(!defined("METAL_LIBRARY_XML_XML_WRITER_CLASS"))
{
define("METAL_LIBRARY_XML_XML_WRITER_CLASS",1);
/*
*
* Copyright © (C) Manuel Lemos 2001-2002
*
* @(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
*
*/
class xml_writer_class
{
/*
* Protected variables
*
*/
var $structure=array();
var $nodes=array();
/*
* Public variables
*
*/
var $stylesheet="";
var $stylesheettype="text/xsl";
var $dtdtype="";
var $dtddefinition="";
var $dtdurl="";
var $outputencoding="utf-8";
var $inputencoding="iso-8859-1";
var $linebreak="\n";
var $indenttext=" ";
var $error="";
/*
* Protected functions
*
*/
Function escapedata($data)
{
$position=0;
$length=strlen($data);
$escapeddata="";
for(;$position<$length;)
{
$character=substr($data,$position,1);
$code=Ord($character);
switch($code)
{
case 34:
$character=""";
break;
case 38:
$character="&";
break;
case 39:
$character="'";
break;
case 60:
$character="<";
break;
case 62:
$character=">";
break;
default:
if($code<32)
$character=("&#".strval($code).";");
break;
}
$escapeddata.=$character;
$position++;
}
return $escapeddata;
}
Function encodedata($data,&$encodeddata)
{
if(!strcmp($this->inputencoding,$this->outputencoding))
$encodeddata=$this->escapedata($data);
else
{
switch(strtolower($this->outputencoding))
{
case "utf-8":
if(!strcmp(strtolower($this->inputencoding),"iso-8859-1"))
{
$encoded_data=utf8_encode($this->escapedata($data));
$encodeddata=$encoded_data;
}
else
{
$this->error=("can not encode iso-8859-1 data in ".$this->outputencoding);
return 0;
}
break;
case "iso-8859-1":
if(!strcmp(strtolower($this->inputencoding),"utf-8"))
{
$decoded=utf8_decode($data);
$encodeddata=$this->escapedata($decoded);
}
else
{
$this->error=("can not encode utf-8 data in ".$this->outputencoding);
return 0;
}
break;
default:
$this->error=("can not encode data in ".$this->inputencoding);
return 0;
}
}
return 1;
}
Function writetag(&$output,$path,$indent)
{
$tag=$this->structure[$path]["Tag"];
$output.=("<".$tag);
$attributecount=count($this->structure[$path]["Attributes"]);
if($attributecount>0)
{
$attributes=$this->structure[$path]["Attributes"];
Reset($attributes);
$end=(GetType($key=Key($attributes))!="string");
for(;!$end;)
{
$output.=(" ".$key."=\"".$attributes[$key]."\"");
Next($attributes);
$end=(GetType($key=Key($attributes))!="string");
}
}
$elements=$this->structure[$path]["Elements"];
if($elements>0)
{
$output.=">";
$doindent=$this->structure[$path]["Indent"];
$elementindent=(($doindent) ? $this->linebreak.$indent.$this->indenttext : "");
$element=0;
for(;$element<$elements;)
{
$elementpath=($path.",".strval($element));
$output.=$elementindent;
if(IsSet($this->nodes[$elementpath]))
{
if(!($this->writetag($output,$elementpath,$indent.$this->indenttext)))
return 0;
}
else
$output.=$this->structure[$elementpath];
$element++;
}
$output.=((($doindent) ? $this->linebreak.$indent : "")."</".$tag.">");
}
else
$output.="/>";
return 1;
}
/*
* Public functions
*
*/
Function write(&$output)
{
if(strcmp($this->error,""))
return 0;
if(!(IsSet($this->structure["0"])))
{
$this->error="XML document structure is empty";
return 0;
}
$output=("<?xml version=\"1.0\" encoding=\"".$this->outputencoding."\"?>".$this->linebreak);
if(strcmp($this->dtdtype,""))
{
$output.=("<!DOCTYPE ".$this->structure["0"]["Tag"]." ");
switch($this->dtdtype)
{
case "INTERNAL":
if(!strcmp($this->dtddefinition,""))
{
$this->error="it was not specified a valid internal DTD definition";
return 0;
}
$output.=("[".$this->linebreak.$this->dtddefinition.$this->linebreak."]");
break;
case "SYSTEM":
if(!strcmp($this->dtdurl,""))
{
$this->error="it was not specified a valid system DTD url";
return 0;
}
$output.="SYSTEM";
if(strcmp($this->dtddefinition,""))
$output.=(" \"".$this->dtddefinition."\"");
$output.=(" \"".$this->dtdurl."\"");
break;
case "PUBLIC":
if(!strcmp($this->dtddefinition,""))
{
$this->error="it was not specified a valid public DTD definition";
return 0;
}
$output.=("PUBLIC \"".$this->dtddefinition."\"");
if(strcmp($this->dtdurl,""))
$output.=(" \"".$this->dtdurl."\"");
break;
default:
$this->error="it was not specified a valid DTD type";
return 0;
}
$output.=(">".$this->linebreak);
}
if(strcmp($this->stylesheet,""))
{
if(!strcmp($this->stylesheettype,""))
{
$this->error="it was not specified a valid stylesheet type";
return 0;
}
$output.=("<?xml-stylesheet type=\"".$this->stylesheettype."\" href=\"".$this->stylesheet."\"?>".$this->linebreak);
}
return $this->writetag($output,"0","");
}
Function addtag($tag,&$attributes,$parent,&$path,$indent)
{
if(strcmp($this->error,""))
return 0;
$path=((!strcmp($parent,"")) ? "0" : ($parent.",".strval($this->structure[$parent]["Elements"])));
if(IsSet($this->structure[$path]))
{
$this->error=("tag with path ".$path." is already defined");
return 0;
}
$encodedattributes=array();
Reset($attributes);
$end=(GetType($attribute_name=Key($attributes))!="string");
for(;!$end;)
{
$encodedattributes[$attribute_name]="";
if(!($this->encodedata($attributes[$attribute_name],$encoded_data)))
return 0;
$encodedattributes[$attribute_name]=$encoded_data;
Next($attributes);
$end=(GetType($attribute_name=Key($attributes))!="string");
}
$this->structure[$path]=array(
"Tag"=>$tag,
"Attributes"=>$encodedattributes,
"Elements"=>0,
"Indent"=>$indent
);
$this->nodes[$path]=1;
if(strcmp($parent,""))
$this->structure[$parent]["Elements"]=($this->structure[$parent]["Elements"]+1);
return 1;
}
Function adddata($data,$parent,&$path)
{
if(strcmp($this->error,""))
return 0;
if(!(IsSet($this->structure[$parent])))
{
$this->error=("the parent tag path".$path."is not defined");
return 0;
}
if(!strcmp($data,""))
return 1;
$path=($parent.",".strval($this->structure[$parent]["Elements"]));
if(!($this->encodedata($data,$encoded_data)))
return 0;
$this->structure[$path]=$encoded_data;
$this->structure[$parent]["Elements"]=($this->structure[$parent]["Elements"]+1);
return 1;
}
Function adddatatag($tag,&$attributes,$data,$parent,&$path)
{
return $this->addtag($tag,$attributes,$parent,$path,0) && $this->adddata($data,$path,$datapath);
}
};
}
?>
|
- Java class generated from MetaL source code
Example of the Java code generated from the MetaL source code above.
/*
*
* Copyright © (C) Manuel Lemos 2001-2002
*
* @(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
*
*/
import java.util.Hashtable;
public class xml_writer_class
{
protected Hashtable structure=new Hashtable();
protected Hashtable nodes=new Hashtable();
public String stylesheet="";
public String stylesheettype="text/xsl";
public String dtdtype="";
public String dtddefinition="";
public String dtdurl="";
public String outputencoding="utf-8";
public String inputencoding="iso-8859-1";
public String linebreak="\n";
public String indenttext=" ";
public String error="";
protected String escapedata(String data)
{
int position;
int length;
String escapeddata;
String character;
int code;
position=0;
length=data.length();
escapeddata="";
for(;position<length;)
{
character=data.substring(position,position+1);
code=(int)(character.charAt(0));
switch(code)
{
case 34:
character=""";
break;
case 38:
character="&";
break;
case 39:
character="'";
break;
case 60:
character="<";
break;
case 62:
character=">";
break;
default:
if(code<32)
character=("&#"+java.lang.String.valueOf(code)+";");
break;
}
escapeddata=escapeddata.concat(character);
position++;
}
return escapeddata;
}
protected boolean encodedata(String data, String[] encodeddata) throws java.io.UnsupportedEncodingException
{
String _switch_value;
String encoded_data;
String decoded;
if(this.inputencoding.equals(this.outputencoding))
encodeddata[0]=this.escapedata(data);
else
{
_switch_value=this.outputencoding.toLowerCase();
switch(_switch_value.equals("utf-8") ? 0 : (_switch_value.equals("iso-8859-1") ? 1 : 2))
{
case 0:
if(this.inputencoding.toLowerCase().equals("iso-8859-1"))
{
encoded_data=new String(this.escapedata(data).getBytes("UTF8"));
encodeddata[0]=encoded_data;
}
else
{
this.error=("can not encode iso-8859-1 data in "+this.outputencoding);
return false;
}
break;
case 1:
if(this.inputencoding.toLowerCase().equals("utf-8"))
{
decoded=new String(data.getBytes(),"UTF8");
encodeddata[0]=this.escapedata(decoded);
}
else
{
this.error=("can not encode utf-8 data in "+this.outputencoding);
return false;
}
break;
default:
this.error=("can not encode data in "+this.inputencoding);
return false;
}
}
return true;
}
protected boolean writetag(String[] output, String path, String indent)
{
String tag;
int attributecount;
Hashtable attributes;
String key;
boolean end;
Object cursor;
int elements;
boolean doindent;
String elementindent;
int element;
String elementpath;
tag=((String)((Hashtable)this.structure.get(path)).get("Tag"));
output[0]=output[0].concat(("<"+tag));
attributecount=((Hashtable)((Hashtable)this.structure.get(path)).get("Attributes")).size();
if(attributecount>0)
{
attributes=((Hashtable)((Hashtable)this.structure.get(path)).get("Attributes"));
cursor=(Object)attributes.keys();
end=!((java.util.Enumeration)cursor).hasMoreElements();
key=end ? null : (String)((java.util.Enumeration)cursor).nextElement();
for(;!end;)
{
output[0]=output[0].concat((" "+key+"=\""+((String)attributes.get(key))+"\""));
end=!((java.util.Enumeration)cursor).hasMoreElements();
key=end ? null : (String)((java.util.Enumeration)cursor).nextElement();
}
}
elements=((Integer)((Hashtable)this.structure.get(path)).get("Elements")).intValue();
if(elements>0)
{
output[0]=output[0].concat(">");
doindent=((Boolean)((Hashtable)this.structure.get(path)).get("Indent")).booleanValue();
elementindent=((doindent) ? this.linebreak+indent+this.indenttext : "");
element=0;
for(;element<elements;)
{
elementpath=(path+","+java.lang.String.valueOf(element));
output[0]=output[0].concat(elementindent);
if(this.nodes.containsKey(elementpath))
{
if(!(this.writetag(output,elementpath,indent+this.indenttext)))
return false;
}
else
output[0]=output[0].concat(((String)this.structure.get(elementpath)));
element++;
}
output[0]=output[0].concat((((doindent) ? this.linebreak+indent : "")+"</"+tag+">"));
}
else
output[0]=output[0].concat("/>");
return true;
}
public boolean write(String[] output)
{
String _switch_value;
if(!this.error.equals(""))
return false;
if(!(this.structure.containsKey("0")))
{
this.error="XML document structure is empty";
return false;
}
output[0]=("<?xml version=\"1.0\" encoding=\""+this.outputencoding+"\"?>"+this.linebreak);
if(!this.dtdtype.equals(""))
{
output[0]=output[0].concat(("<!DOCTYPE "+((String)((Hashtable)this.structure.get("0")).get("Tag"))+" "));
_switch_value=this.dtdtype;
switch(_switch_value.equals("INTERNAL") ? 0 : (_switch_value.equals("SYSTEM") ? 1 : (_switch_value.equals("PUBLIC") ? 2 : 3)))
{
case 0:
if(this.dtddefinition.equals(""))
{
this.error="it was not specified a valid internal DTD definition";
return false;
}
output[0]=output[0].concat(("["+this.linebreak+this.dtddefinition+this.linebreak+"]"));
break;
case 1:
if(this.dtdurl.equals(""))
{
this.error="it was not specified a valid system DTD url";
return false;
}
output[0]=output[0].concat("SYSTEM");
if(!this.dtddefinition.equals(""))
output[0]=output[0].concat((" \""+this.dtddefinition+"\""));
output[0]=output[0].concat((" \""+this.dtdurl+"\""));
break;
case 2:
if(this.dtddefinition.equals(""))
{
this.error="it was not specified a valid public DTD definition";
return false;
}
output[0]=output[0].concat(("PUBLIC \""+this.dtddefinition+"\""));
if(!this.dtdurl.equals(""))
output[0]=output[0].concat((" \""+this.dtdurl+"\""));
break;
default:
this.error="it was not specified a valid DTD type";
return false;
}
output[0]=output[0].concat((">"+this.linebreak));
}
if(!this.stylesheet.equals(""))
{
if(this.stylesheettype.equals(""))
{
this.error="it was not specified a valid stylesheet type";
return false;
}
output[0]=output[0].concat(("<?xml-stylesheet type=\""+this.stylesheettype+"\" href=\""+this.stylesheet+"\"?>"+this.linebreak));
}
return this.writetag(output,"0","");
}
public boolean addtag(String tag, Hashtable attributes, String parent, String[] path, boolean indent) throws java.io.UnsupportedEncodingException
{
Hashtable encodedattributes;
String attribute_name;
boolean end;
Object cursor;
String[] encoded_data={null};
if(!this.error.equals(""))
return false;
path[0]=((parent.equals("")) ? "0" : (parent+","+java.lang.String.valueOf(((Integer)((Hashtable)this.structure.get(parent)).get("Elements")).intValue())));
if(this.structure.containsKey(path[0]))
{
this.error=("tag with path "+path[0]+" is already defined");
return false;
}
encodedattributes=new Hashtable();
cursor=(Object)attributes.keys();
end=!((java.util.Enumeration)cursor).hasMoreElements();
attribute_name=end ? null : (String)((java.util.Enumeration)cursor).nextElement();
for(;!end;)
{
encodedattributes.put(attribute_name,"");
if(!(this.encodedata(((String)attributes.get(attribute_name)),encoded_data)))
return false;
encodedattributes.put(attribute_name,encoded_data[0]);
end=!((java.util.Enumeration)cursor).hasMoreElements();
attribute_name=end ? null : (String)((java.util.Enumeration)cursor).nextElement();
}
{
Hashtable _hashtable=new Hashtable(4);
_hashtable.put("Tag",tag);
_hashtable.put("Attributes",encodedattributes);
_hashtable.put("Elements",new Integer(0));
_hashtable.put("Indent",new Boolean(indent));
this.structure.put(path[0],_hashtable);
}
this.nodes.put(path[0],new Boolean(true));
if(!parent.equals(""))
((Hashtable)this.structure.get(parent)).put("Elements",new Integer((((Integer)((Hashtable)this.structure.get(parent)).get("Elements")).intValue()+1)));
return true;
}
public boolean adddata(String data, String parent, String[] path) throws java.io.UnsupportedEncodingException
{
String[] encoded_data={null};
if(!this.error.equals(""))
return false;
if(!(this.structure.containsKey(parent)))
{
this.error=("the parent tag path"+path[0]+"is not defined");
return false;
}
if(data.equals(""))
return true;
path[0]=(parent+","+java.lang.String.valueOf(((Integer)((Hashtable)this.structure.get(parent)).get("Elements")).intValue()));
if(!(this.encodedata(data,encoded_data)))
return false;
this.structure.put(path[0],encoded_data[0]);
((Hashtable)this.structure.get(parent)).put("Elements",new Integer((((Integer)((Hashtable)this.structure.get(parent)).get("Elements")).intValue()+1)));
return true;
}
public boolean adddatatag(String tag, Hashtable attributes, String data, String parent, String[] path) throws java.io.UnsupportedEncodingException
{
String[] datapath={null};
return this.addtag(tag,attributes,parent,path,false) && this.adddata(data,path[0],datapath);
}
};
|
- Template for class documentation written in MetaL
Example a template definition of class documentation that is independent of the target document format and of the target programming language.
<?xml version="1.0"?>
<!--
@(#) $Header: /home/mlemos/cvsroot/metalweb/web/sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
-->
<document>
<title>Class: <getclassproperty>title</getclassproperty></title>
<author><getclassproperty>author</getclassproperty></author>
<authoraddress><getclassproperty>authoraddress</getclassproperty></authoraddress>
<body>
<list>
<p><b>Version:</b> <tt><getclassproperty>version</getclassproperty></tt></p>
<heading><link>
<data>Contents</data>
<anchor>table_of_contents</anchor>
</link></heading>
<tableofcontents />
<p><link>
<data>Top of the table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
<sectionbreak />
<list>
<heading><li><mark>Summary</mark></li></heading>
<list>
<heading><mark>Name</mark></heading>
<p><getclassproperty>title</getclassproperty></p>
<heading><mark>Author</mark></heading>
<p><getclassproperty>author</getclassproperty> (<link>
<data><getclassproperty>authoraddress</getclassproperty></data>
<url>mailto:<getclassproperty>authoraddress</getclassproperty></url>
</link>)</p>
<conditionalvalue>
<istrue><definedclassproperty>copyright</definedclassproperty></istrue>
<then><heading><mark>Copyright</mark></heading><p><getclassproperty>copyright</getclassproperty></p></then>
</conditionalvalue>
<heading><mark>Version</mark></heading>
<p><getclassproperty>version</getclassproperty></p>
<conditionalvalue>
<istrue><getclassproperty>subclass</getclassproperty></istrue>
<then><heading><mark>Parent classes</mark></heading><list><forallparentclasses><p><li><getsubclassproperty>title</getsubclassproperty><conditionalvalue><istrue><getsubclassproperty>abstract</getsubclassproperty></istrue><then> (abstract)</then></conditionalvalue></li></p><p><b>Version:</b> <tt><getsubclassproperty>version</getsubclassproperty></tt></p></forallparentclasses></list></then>
</conditionalvalue>
<heading><mark>Purpose</mark></heading>
<p><getclassdocumentation>purpose</getclassdocumentation></p>
<heading><mark>Usage</mark></heading>
<p><getclassdocumentation>usage</getclassdocumentation></p>
<conditionalvalue>
<istrue><definedclassdocumentation>example</definedclassdocumentation></istrue>
<then><heading><mark>Example</mark></heading><p><getclassdocumentation>example</getclassdocumentation></p></then>
</conditionalvalue>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
</list>
<sectionbreak />
<list>
<heading><li><link>
<data></data>
<anchor>variables</anchor>
</link><mark>Variables</mark></li></heading>
<list>
<forallpublicvariables><li><variablelink><variablename /></variablelink></li><br /></forallpublicvariables>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
<forallpublicvariables>
<heading><link>
<data></data>
<anchor><variableanchor>
<arguments>
<variable><variablename /></variable>
</arguments>
</variableanchor></anchor>
</link><li><mark><variablename /></mark></li></heading>
<heading>Type</heading>
<p><tt><i><variabletypename /></i></tt></p>
<conditionalvalue>
<istrue><definedvariabledefaultvalue /></istrue>
<then><heading>Default value</heading><p><tt><variableconvertedvalue /></tt></p></then>
</conditionalvalue>
<heading>Purpose</heading>
<p><conditionalvalue>
<istrue><definedclassdocumentation>purpose</definedclassdocumentation></istrue>
<then><getclassdocumentation>purpose</getclassdocumentation></then>
<else>Not yet documented.</else>
</conditionalvalue></p>
<conditionalvalue>
<istrue><definedclassdocumentation>usage</definedclassdocumentation></istrue>
<then><heading>Usage</heading><p><getclassdocumentation>usage</getclassdocumentation></p></then>
</conditionalvalue>
<conditionalvalue>
<istrue><definedclassdocumentation>example</definedclassdocumentation></istrue>
<then><heading>Example</heading><p><getclassdocumentation>example</getclassdocumentation></p></then>
</conditionalvalue>
<p><link>
<data>Variables</data>
<name>variables</name>
</link></p>
</forallpublicvariables>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
</list>
<conditionalvalue>
<istrue><getclassproperty>subclass</getclassproperty></istrue>
<then><list>
<heading><li><link>
<data></data>
<anchor>functions</anchor>
</link><mark>Inherited variables</mark></li></heading>
<list>
<forallpublicinheritedvariables><li><variablename /></li><br /></forallpublicinheritedvariables>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
</list></then>
</conditionalvalue>
<sectionbreak />
<list>
<heading><li><link>
<data></data>
<anchor>functions</anchor>
</link><mark>Functions</mark></li></heading>
<list>
<forallpublicfunctions><li><functionlink><functionname /></functionlink></li><br /></forallpublicfunctions>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
<forallpublicfunctions>
<heading><link>
<data></data>
<anchor><functionanchor>
<arguments>
<function><functionname /></function>
</arguments>
</functionanchor></anchor>
</link><li><mark><functionname /></mark></li></heading>
<heading>Synopsis</heading>
<p><tt><i><functiontypename /></i> <functionname />(</tt><conditionalvalue>
<istrue><functionhasarguments /></istrue>
<then><list>
<forallarguments><tt><conditionalvalue>
<istrue><inoutargument /></istrue>
<then>(input and output) </then>
<else><conditionalvalue>
<istrue><outargument /></istrue>
<then>(output) </then>
</conditionalvalue></else>
</conditionalvalue><i><argumenttypename /></i> </tt><argumentlink>
<function><functionname /></function>
<argument><argumentname /></argument>
</argumentlink><tt><conditionalvalue>
<isfalse><lastargument /></isfalse>
<then>,<br /></then>
</conditionalvalue></tt></forallarguments>
</list></then>
</conditionalvalue><tt>)</tt></p>
<heading>Purpose</heading>
<p><conditionalvalue>
<istrue><definedclassdocumentation>purpose</definedclassdocumentation></istrue>
<then><getclassdocumentation>purpose</getclassdocumentation></then>
<else>Not yet documented.</else>
</conditionalvalue></p>
<conditionalvalue>
<istrue><definedclassdocumentation>usage</definedclassdocumentation></istrue>
<then><heading>Usage</heading><p><getclassdocumentation>usage</getclassdocumentation></p></then>
</conditionalvalue>
<conditionalvalue>
<istrue><functionhasarguments /></istrue>
<then><heading>Arguments</heading><list>
<forallarguments><p><tt><b><link>
<data><argumentname /></data>
<anchor><argumentanchor>
<arguments>
<function><functionname /></function>
<argument><argumentname /></argument>
</arguments>
</argumentanchor></anchor>
</link></b></tt> - <conditionalvalue>
<istrue><definedclassdocumentation>purpose</definedclassdocumentation></istrue>
<then><getclassdocumentation>purpose</getclassdocumentation></then>
<else>Not yet documented.</else>
</conditionalvalue></p></forallarguments>
</list></then>
</conditionalvalue>
<conditionalvalue>
<isfalse><functionistype>VOID</functionistype></isfalse>
<then><heading>Return value</heading><p><conditionalvalue>
<istrue><definedclassdocumentation>returnvalue</definedclassdocumentation></istrue>
<then><getclassdocumentation>returnvalue</getclassdocumentation></then>
<else>Not yet documented.</else>
</conditionalvalue></p></then>
</conditionalvalue>
<conditionalvalue>
<istrue><definedclassdocumentation>example</definedclassdocumentation></istrue>
<then><heading>Example</heading><p><getclassdocumentation>example</getclassdocumentation></p></then>
</conditionalvalue>
<p><link>
<data>Functions</data>
<name>functions</name>
</link></p>
</forallpublicfunctions>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
</list>
<conditionalvalue>
<istrue><getclassproperty>subclass</getclassproperty></istrue>
<then><list>
<heading><li><link>
<data></data>
<anchor>functions</anchor>
</link><mark>Inherited functions</mark></li></heading>
<list>
<forallpublicinheritedfunctions><li><functionname /></li><br /></forallpublicinheritedfunctions>
<p><link>
<data>Table of contents</data>
<name>table_of_contents</name>
</link></p>
</list>
</list></then>
</conditionalvalue>
</body>
</document>
|
- Class documentation automatically generated with PHP syntax
Example of HTML documentation generated automatically with PHP syntax from the MetaL source code above.
Class: XML writer
- Summary
XML writer
Manuel Lemos (mlemos@acm.org)
Copyright © (C) Manuel Lemos 2001-2002
@(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
Composing and generating XML documents.
The class has several independent functions that should be used to compose the structure of an XML document. When the structure is fully composed, the write should be used to output the document in the XML format.
Here follows an example of typical use of this class:
<?php
/*
* First create an object of the class.
*/
$xml_writer_object=new xml_writer_class;
/*
* Now, start defining the XML document from the root tag.
*/
$noattributes=array();
$xml_writer_object->addtag("myxmldocument",$noattributes,"",$root,1);
/*
* Then define the rest of the document tags and data.
*/
$xml_writer_object->addtag("name",$noattributes,$root,$toptag,0);
$xml_writer_object->adddata("John Doe",$toptag,$path);
/*
* Tags may have attributes.
*/
$attributes=array();
$attributes["country"]="us";
$xml_writer_object->addtag("address",$attributes,$root,$toptag,1);
/*
* Tags and the correspondent data may be added with a single function call.
*/
$xml_writer_object->adddatatag("street",$noattributes,"Wall Street, 1641",$toptag,$datatag);
$xml_writer_object->adddatatag("zip",$noattributes,"NY 72834",$toptag,$datatag);
/*
* Any time before generating the document you may specify a DTD to let other tools validate it...
*/
$xml_writer_object->dtdtype="SYSTEM";
$xml_writer_object->dtdurl="myxmldocument.dtd";
/*
* ...and a stylesheet for displaying the document in particular way in XML capable browsers.
*/
$xml_writer_object->stylesheettype="text/xsl";
$xml_writer_object->stylesheet="myxmldocument.xsl";
/*
* When you are done with the XML document definition, generate it.
*/
if($xml_writer_object->write($output))
{
/*
* If the document was generated successfully, you may not output it.
*/
echo $output;
}
else
{
/*
* If there was an error, output it as well.
*/
echo ("Error: ".$xml_writer_object->error);
}
?>
Table of contents
- Variables
- stylesheet
- stylesheettype
- dtdtype
- dtddefinition
- dtdurl
- outputencoding
- inputencoding
- linebreak
- indenttext
- error
Table of contents
- stylesheet
Type
string
Default value
""
Purpose
Define the URL for the default stylesheet definition to be used render the XML document.
Usage
If you intend that browsers display this document in specific way define the URL of where it is located the stylesheet to be used to render the document. Set this variable to an empty string if you do not intend to specify a stylesheet.
Variables
- stylesheettype
Type
string
Default value
"text/xsl"
Purpose
Stylesheets may be of several types. This variable defines the MIME content type of the stylesheet specified for this document.
Usage
Set this variable to MIME designation for the type of stylesheet defined by the variable stylesheet.
Example
"text/css"
Variables
- dtdtype
Type
string
Default value
""
Purpose
Define which type of document type definition (DTD).
Usage
If you intend to specify a DTD, eventually for validation purposes, set this variable to either: "INTERNAL", "SYSTEM" or "PUBLIC". Set this variable to an empty string to not use a DTD. "INTERNAL" mean that the DTD is bein defined inline within the dtddefinition variable. "SYSTEM" or "PUBLIC" means that the DTD is defined in an external resource defined by either dtddefinition or dtdurl.
Variables
- dtddefinition
Type
string
Default value
""
Purpose
Define of the DTD.
Usage
For an internal DTD, this variable should contain the actual DTD definition. For an external DTD, it should be of the form "Registration//Organization//Type Label//Definition Language".
Example
Example of an internal DTD definition:
"<!ELEMENT html (head, body)>\n<!ELEMENT head (title?)>\n<!ELEMENT title (#PCDATA)>\n<!ELEMENT body (#PCDATA)>\n"
Example of an external DTD definition:
"-//W3C//DTD XHTML 1.0 Strict//EN"
Variables
- dtdurl
Type
string
Default value
""
Purpose
Define the URL of an external DTD.
Usage
Optionally specify an absolute or relative URL of an external DTD.
Example
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
Variables
- outputencoding
Type
string
Default value
"utf-8"
Purpose
Define the character set encoding of the output document.
Usage
Currently the class supports only the encodings utf-8 or iso-8859-1.
Variables
- inputencoding
Type
string
Default value
"iso-8859-1"
Purpose
Define the character set encoding of the of the data values passed to the function adddata or the attribute values passed to the function addtag.
Usage
Currently the class supports only the encodings utf-8 or iso-8859-1.
Variables
- linebreak
Type
string
Default value
"\n"
Purpose
Characters to be used when breaking lines of the output XML document.
Usage
Use either "\n", "\r\n" or "\r".
Variables
- indenttext
Type
string
Default value
" "
Purpose
Characters to be used when indenting the lines of the output XML document.
Usage
Use either one or more spaces or tab characters.
Variables
- error
Type
string
Default value
""
Purpose
Contains the error message that explains the reason of failure of certain class functions.
Usage
Check this variable when a given class function fails.
Variables
Table of contents
- Functions
- write
- addtag
- adddata
- adddatatag
Table of contents
- write
Synopsis
bool write(
)
Purpose
Generate the XML document.
Usage
Pass a reference to a string variable that will hold the resulting XML document.
Arguments
Return value
Success boolean flag. If this flag is 0 then the error variable contains the error message that explains the failure.
Functions
- addtag
Synopsis
bool addtag(
)
Purpose
Add a tag to the XML document structure.
Usage
Specify the tag definition and the parent XML document element where the tag will be added.
Arguments
tag - Name of the tag to be added.
attributes - Associative array that defines the list of attributes of the tag, if any. The indexes of the array entries are the names of the attributes and the values array entries are the attribute values defined in encoding type specified by the inputencoding variable.
parent - Path of the parent XML document tag element within each which the new tag is being added. If the new tag is the document root tag, the parent path is "". The path of previously added tags is returned by the path argument of previous calls to this function.
path - Reference to a variable that will hold the path of the XML document tag element that is added by this function.
indent - Flag that determines if the elements to be added within this tag will be outputted in individual indented lines.
Return value
Success boolean flag. If this flag is 0 then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
- adddata
Synopsis
bool adddata(
)
Purpose
Add a data part to the XML document structure.
Usage
Specify the data text and the parent XML document element where the tag will be added.
Arguments
data - Data text to be added.
parent - Path of the parent XML document tag element within each which the new data part is being added. The path of previously added tags is returned by the path argument of previous calls to the addtag function.
path - Reference to a variable that will hold the path of the XML document data part element that is added by this function.
Return value
Success boolean flag. If this flag is 0 then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
- adddatatag
Synopsis
bool adddatatag(
)
Purpose
Add a tag with data to the XML document structure.
Usage
Specify the tag definition, the text data and the parent XML document element where the tag will be added.
Arguments
tag - Name of the tag to be added.
attributes - Associative array that defines the list of attributes of the tag, if any. The indexes of the array entries are the names of the attributes and the values array entries are the attribute values defined in encoding type specified by the inputencoding variable.
data - Data text to be added.
parent - Path of the parent XML document tag element within each which the new tag is being added. The path of previously added tags is returned by the path argument of previous calls to the addtag function.
path - Reference to a variable that will hold the path of the XML document tag element that is added by this function.
Return value
Success boolean flag. If this flag is 0 then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
Table of contents
|
- Class documentation automatically generated with Java syntax
Example of HTML documentation generated automatically with Java syntax from the MetaL source code above.
Class: XML writer
- Summary
XML writer
Manuel Lemos (mlemos@acm.org)
Copyright © (C) Manuel Lemos 2001-2002
@(#) $Id: sample.html,v 1.7 2006/01/12 19:51:37 mlemos Exp $
Composing and generating XML documents.
The class has several independent functions that should be used to compose the structure of an XML document. When the structure is fully composed, the write should be used to output the document in the XML format.
Here follows an example of typical use of this class:
{
Object xml_writer_object;
Hashtable noattributes;
String[] root={null};
String[] toptag={null};
String[] path={null};
Hashtable attributes;
String[] datatag={null};
String[] output={null};
/*
* First create an object of the class.
*/
xml_writer_object=new xml_writer_class();
/*
* Now, start defining the XML document from the root tag.
*/
noattributes=new Hashtable();
xml_writer_object.addtag("myxmldocument",noattributes,"",root,true);
/*
* Then define the rest of the document tags and data.
*/
xml_writer_object.addtag("name",noattributes,root[0],toptag,false);
xml_writer_object.adddata("John Doe",toptag[0],path);
/*
* Tags may have attributes.
*/
attributes=new Hashtable();
attributes.put("country","us");
xml_writer_object.addtag("address",attributes,root[0],toptag,true);
/*
* Tags and the correspondent data may be added with a single function call.
*/
xml_writer_object.adddatatag("street",noattributes,"Wall Street, 1641",toptag[0],datatag);
xml_writer_object.adddatatag("zip",noattributes,"NY 72834",toptag[0],datatag);
/*
* Any time before generating the document you may specify a DTD to let other tools validate it...
*/
xml_writer_object.dtdtype="SYSTEM";
xml_writer_object.dtdurl="myxmldocument.dtd";
/*
* ...and a stylesheet for displaying the document in particular way in XML capable browsers.
*/
xml_writer_object.stylesheettype="text/xsl";
xml_writer_object.stylesheet="myxmldocument.xsl";
/*
* When you are done with the XML document definition, generate it.
*/
if(xml_writer_object.write(output))
{
/*
* If the document was generated successfully, you may not output it.
*/
System.out.print(output[0]);
}
else
{
/*
* If there was an error, output it as well.
*/
System.out.print(("Error: "+xml_writer_object.error));
}
}
Table of contents
- Variables
- stylesheet
- stylesheettype
- dtdtype
- dtddefinition
- dtdurl
- outputencoding
- inputencoding
- linebreak
- indenttext
- error
Table of contents
- stylesheet
Type
String
Default value
""
Purpose
Define the URL for the default stylesheet definition to be used render the XML document.
Usage
If you intend that browsers display this document in specific way define the URL of where it is located the stylesheet to be used to render the document. Set this variable to an empty string if you do not intend to specify a stylesheet.
Variables
- stylesheettype
Type
String
Default value
"text/xsl"
Purpose
Stylesheets may be of several types. This variable defines the MIME content type of the stylesheet specified for this document.
Usage
Set this variable to MIME designation for the type of stylesheet defined by the variable stylesheet.
Example
"text/css"
Variables
- dtdtype
Type
String
Default value
""
Purpose
Define which type of document type definition (DTD).
Usage
If you intend to specify a DTD, eventually for validation purposes, set this variable to either: "INTERNAL", "SYSTEM" or "PUBLIC". Set this variable to an empty string to not use a DTD. "INTERNAL" mean that the DTD is bein defined inline within the dtddefinition variable. "SYSTEM" or "PUBLIC" means that the DTD is defined in an external resource defined by either dtddefinition or dtdurl.
Variables
- dtddefinition
Type
String
Default value
""
Purpose
Define of the DTD.
Usage
For an internal DTD, this variable should contain the actual DTD definition. For an external DTD, it should be of the form "Registration//Organization//Type Label//Definition Language".
Example
Example of an internal DTD definition:
"<!ELEMENT html (head, body)>\n<!ELEMENT head (title?)>\n<!ELEMENT title (#PCDATA)>\n<!ELEMENT body (#PCDATA)>\n"
Example of an external DTD definition:
"-//W3C//DTD XHTML 1.0 Strict//EN"
Variables
- dtdurl
Type
String
Default value
""
Purpose
Define the URL of an external DTD.
Usage
Optionally specify an absolute or relative URL of an external DTD.
Example
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
Variables
- outputencoding
Type
String
Default value
"utf-8"
Purpose
Define the character set encoding of the output document.
Usage
Currently the class supports only the encodings utf-8 or iso-8859-1.
Variables
- inputencoding
Type
String
Default value
"iso-8859-1"
Purpose
Define the character set encoding of the of the data values passed to the function adddata or the attribute values passed to the function addtag.
Usage
Currently the class supports only the encodings utf-8 or iso-8859-1.
Variables
- linebreak
Type
String
Default value
"\n"
Purpose
Characters to be used when breaking lines of the output XML document.
Usage
Use either "\n", "\r\n" or "\r".
Variables
- indenttext
Type
String
Default value
" "
Purpose
Characters to be used when indenting the lines of the output XML document.
Usage
Use either one or more spaces or tab characters.
Variables
- error
Type
String
Default value
""
Purpose
Contains the error message that explains the reason of failure of certain class functions.
Usage
Check this variable when a given class function fails.
Variables
Table of contents
- Functions
- write
- addtag
- adddata
- adddatatag
Table of contents
- write
Synopsis
bool write(
)
Purpose
Generate the XML document.
Usage
Pass a reference to a string variable that will hold the resulting XML document.
Arguments
Return value
Success boolean flag. If this flag is false then the error variable contains the error message that explains the failure.
Functions
- addtag
Synopsis
bool addtag(
)
Purpose
Add a tag to the XML document structure.
Usage
Specify the tag definition and the parent XML document element where the tag will be added.
Arguments
tag - Name of the tag to be added.
attributes - Associative array that defines the list of attributes of the tag, if any. The indexes of the array entries are the names of the attributes and the values array entries are the attribute values defined in encoding type specified by the inputencoding variable.
parent - Path of the parent XML document tag element within each which the new tag is being added. If the new tag is the document root tag, the parent path is "". The path of previously added tags is returned by the path argument of previous calls to this function.
path - Reference to a variable that will hold the path of the XML document tag element that is added by this function.
indent - Flag that determines if the elements to be added within this tag will be outputted in individual indented lines.
Return value
Success boolean flag. If this flag is false then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
- adddata
Synopsis
bool adddata(
)
Purpose
Add a data part to the XML document structure.
Usage
Specify the data text and the parent XML document element where the tag will be added.
Arguments
data - Data text to be added.
parent - Path of the parent XML document tag element within each which the new data part is being added. The path of previously added tags is returned by the path argument of previous calls to the addtag function.
path - Reference to a variable that will hold the path of the XML document data part element that is added by this function.
Return value
Success boolean flag. If this flag is false then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
- adddatatag
Synopsis
bool adddatatag(
)
Purpose
Add a tag with data to the XML document structure.
Usage
Specify the tag definition, the text data and the parent XML document element where the tag will be added.
Arguments
tag - Name of the tag to be added.
attributes - Associative array that defines the list of attributes of the tag, if any. The indexes of the array entries are the names of the attributes and the values array entries are the attribute values defined in encoding type specified by the inputencoding variable.
data - Data text to be added.
parent - Path of the parent XML document tag element within each which the new tag is being added. The path of previously added tags is returned by the path argument of previous calls to the addtag function.
path - Reference to a variable that will hold the path of the XML document tag element that is added by this function.
Return value
Success boolean flag. If this flag is false then the error variable contains the error message that explains the failure. This return value may be safely ignored if the function call arguments are correctly defined.
Functions
Table of contents
|
|