ttlogo.jpg Free TextTransformer Projects
Home
Text2HTML
Wikipedia
Yacc2TT
Delphi parser
Java parser
C preprocessor
C parser
HTML4
Utilities
XML-Writer
MergeHTML
RtfCheck
Zahl2Nombre
MIME parser
Spamfilter
Additional Examples
Free components
  Minimal Website   Impressum

XML-Writer


XML (eXtensible Markup Language) is a very widespread standard by which an exchange of data between different applications and over the WEB is possible. At first the data must be brought in XML form, however. This is relatively simple, once a text is parsed. For this TextTransformer is an ideal tool because parsers for all kinds of texts can be produced with it relatively easily. The functions which are then necessary to make a XML file from the parsed text can be downloaded as an import file for the interpreter page of the TextTransformer.

XML_Writer.tte

The use of the functions is demonstrated with the projects "Csv2XML.ttp" and "Csv2TreeXML.ttp", which are a simple parsers for comma separated values.

Csv2XML.ttp
Csv2TreeXML.ttp

The functions are called directly during parsing in "Csv2XML.ttp". In "Csv2TreeXML.ttp" a parse tree is built first and the functions are then used to evaluate this tree.

By these projects you can parse for example the text:

Csv2XMLtest.txt

There are following functions:

"WriteXMLtStart" writes the header of the xml document:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Csv>

"WriteTagStart" writes a tag like: <Line>.

If the tag shall get some attributes, "WriteTagStart" is split into:

  • "WriteTagOpen" writes "<Line"
  • "WriteAttibute" writes an attribute like "Number=1"
  • "WriteTagClose" writes ">"

"WriteTagEnd" (="WriteXMLEnd") writes the end tag like: </Line>.

The content between two tags is written with "WriteXMLContent". This function uses the other function "Encode", which encodes some special characters.

With the vector m_vIndent and with the vector m_vTag stacks of tags and indents are managed.

An elegant possibility of getting a similar XML output without the functions above, is the use of a xerces DOM. This is demonstrated with the following project:

Csv2DOMXML.ttp

Last Update: 09 april 08

 to the top