DOMFormatter Class Reference

Inheritance diagram for DOMFormatter:

< DOMVisitor > List of all members.

Detailed Description

A class for pretty-printing and outputing documents.

Example usage:

 // the object "xml" will hold a string representation of a document
 NSString *xml = [DOMFormatter stringFromNode:document];

 // the document will be written to a file
 [DOMFormatter writeNode:document toFile:@"/tmp/document.xml"];

The output format can be set by tweaking an instance of DOMFormatOptions. See the documentation for that class for more information.


Public Member Functions

(void)  setFormatOptions:
(void)  setContextNode:
(NSString *)  string
(BOOL)  writeToFile:

Static Public Member Functions

(DOMFormatter *)  formatter
(NSString *)  stringFromNode:
(NSString *)  stringFromNode:formatOptions:
(BOOL)  writeNode:toFile:
(BOOL)  writeNode:toFile:formatOptions:

Protected Attributes

DOMFormatOptions formatOptions
id< DOMNode contextNode

Member Function Documentation

+ (DOMFormatter *) formatter  
 

Returns a new formatter.

- (void) setContextNode: (id< DOMNode >)  node  
 

Sets the context document. It is this document that will be formatted and outputed

- (void) setFormatOptions: (DOMFormatOptions *)  options  
 

Sets a new options object as the options used.

- (NSString *) string  
 

Creates a string representation of the document and returns it. The document will be formatted according to the default format options, or alternative format options, if applicable.

Will replace &, <, >, ", and ' with the escaped versions.

No XML prolog will be added to the string, even if that is set in the options. The prolog is however added by writeToFile:. It's not clear whether or not this is the expected behaviour, from reading the XML spec.

+ (NSString *) stringFromNode: (id< DOMNode >)  node  
 

See stringFromNode:formatOptions:

+ (NSString *) stringFromNode: (id< DOMNode >)  node
formatOptions: (DOMFormatOptions *)  options
 
 

Equivalent to:

 DOMFormatter *formatter = [DOMFormatter formatter];
     
 [formatter setContextNode:node];
 [formatter setOptions:[DOMFormatOptions formatOptions]];

 NSString *result = [formatter string];

+ (BOOL) writeNode: (id< DOMNode >)  node
toFile: (NSString *)  path
 
 

See writeNode:toFile:formatOptions:

+ (BOOL) writeNode: (id< DOMNode >)  node
toFile: (NSString *)  path
formatOptions: (DOMFormatOptions *)  options
 
 

Equivalent to:

 DOMFormatter *formatter = [DOMFormatter formatter];
     
 [formatter setContextNode:node];
 [formatter setOptions:[DOMFormatOptions formatOptions]];

 [formatter writeToFile:@"..."];

- (BOOL) writeToFile: (NSString *)  path  
 

Writes the results of string to a file at the specified path.

Currently, the file will be written using UTF-8 encoding. In the future there will be a setting to change this.

If the options are set to include a prolog, it will be added and the encoding will be specified as UTF-8.

Member Data Documentation

- (id<DOMNode>) contextNode [protected]
 

- (DOMFormatOptions*) formatOptions [protected]