Class DXMLWriter

Inherits from:
Object
Conforms to:
DXMLHandler
Declared in:
DXML.h

Class Hierarchy

    Object
      |
      +---DXMLWriter

Class Description

The xml writer class implements methods for writing a xml file. This class does NOT check the correctness of the written xml. The method 'characters' translates the special characters (<,>,&,",'), the method 'unparsed' does not. With the last method an entity or character reference can be written. Linefeeds are never added by the writer. Linefeeds must be supplied by the calling software by using 'characters:' or 'unparsed:'. Use a character that can't be part of an URI e.g. '|' for the namespace separator.

Example:
#include <stdio.h>
#include "ofc/DXML.h"
#include "ofc/DText.h"

int main(int argc, char *argv[])
{
  DXMLWriter *wrtr = [DXMLWriter new];
  DText      *dest = [DText      new];  // Use a text string as destination

  if ([wrtr start :dest :'|'])
  {
    if (![wrtr startDocument :"1.0" :NULL :YES])      // Write start of document
      printf("Could not write start of xml document.\n");

    if (![wrtr comment :"Example of the XMLWriter"])  // Write comment
      printf("Could not write xml comment.\n");

    if (![wrtr startElement :"ELEMENT1"])             // Write start of element
      printf("Could not write start element.\n");

    if (![wrtr attribute :"attribute1" :"value1"])    // Write attribute for element
      printf("Could not write attribute.\n");

    if (![wrtr characters :"Some text & another text."])  // Write norml text
      printf("Could not write normal text.\n");

    if (![wrtr endElement])                           // Write end of element
      printf("Could not write end of element.\n");

    if (![wrtr endDocument])                          // Write end of document
      printf("Could not write end of xml document.\n");

    printf("Result xml document:\n%s\n", [dest cstring]);  // Print result
  }
  else
    printf("Could not start writing xml document.\n");

  [wrtr free];                         // Cleanup
  [dest free];

  return 0;
}
Last modified:
11-Aug-2008 (DXML.h)

Instance Variables

private id <DTextWritable> _dest
the config file
private DList *_elements
the stack with the element names
private DList *_namespaces
the stack with the namespaces
private DList *_unprocessed
the list with the unprocessed namespaces
private BOOL _closeElement
should the last element still be closed ?
private BOOL _inCData
is the writer inside a CDATA section ?
private char _separator
the namespace separator (or EOS for none)

Method Index


generated 06-Sep-2008 by ObjcDoc 3.0.0