DOMFormatOptions Class Reference

List of all members.

Detailed Description

This class encapsulates information on how a document should be formatted when being converted to a string or written to a file.

Currently there are five options:

     <test>
         <string>It is usually not this cold in may</string>
     </test>

This class also encapsulates some logic determining how these options should affect the result. The formatter will query it's options object about when to add a newline, add indentation, and so forth.


Public Member Functions

(void)  setIndentString:
(NSString *)  indentString
(void)  setUsesNewlines:
(BOOL)  usesNewlines
(void)  setIncludeProlog:
(BOOL)  includeProlog
(void)  setNormalizeWhitespace:
(BOOL)  normalizeWhitespace
(void)  inlineContentOfElements:
(BOOL)  elementShouldHaveInlinedContent:
(BOOL)  shouldIndentNode:
(BOOL)  shouldHaveNewlineAfterNode:
(BOOL)  shouldHaveNewlineBeforeNode:

Static Public Member Functions

(DOMFormatOptions *)  formatOptions

Member Function Documentation

- (BOOL) elementShouldHaveInlinedContent: (NSString *)  elementName  
 

Returns true if the element should have inlined content (as specified by inlineContentOfElements:).

+ (DOMFormatOptions*) formatOptions  
 

Returns options object with the default options set.

The default options are:

  • indent string: "\t"
  • use newlines: YES
  • include prolog: YES
  • normalize whitespace: YES
  • don't inline the contents of any elements (except those in mixed content)

- (BOOL) includeProlog  
 

- (NSString *) indentString  
 

- (void) inlineContentOfElements: (NSSet *)  elementNames  
 

The named elements will have their content inlined, that is, there will be no space between the end of the tag and the content.

Elements in mixed content (elements that have text node siblings) will always be inlined.

Parameters:
elementNames The names of the elements that should be inlined in text (ex. ["span", "bold", "name"]), an NSSet of NSStrings

- (BOOL) normalizeWhitespace  
 

- (void) setIncludeProlog: (BOOL)  prolog  
 

- (void) setIndentString: (NSString *)  indent  
 

- (void) setNormalizeWhitespace: (BOOL)  normalize  
 

- (void) setUsesNewlines: (BOOL)  newlines  
 

- (BOOL) shouldHaveNewlineAfterNode: (id< DOMNode >)  node  
 

In these cases there should NOT be a newline after:

  • Nodes whose parent is in mixed content.
  • Nodes in mixed content (unless it is the last one).
  • Nodes with a parent that has been set to have inlined content.

- (BOOL) shouldHaveNewlineBeforeNode: (id< DOMNode >)  node  
 

In these cases there should NOT be a newline before:

  • Nodes whose parent is in mixed content.
  • Nodes with a parent that has been set to have inlined content.

- (BOOL) shouldIndentNode: (id< DOMNode >)  node  
 

Decides which nodes to indent, based on rules and options.

All nodes should be indented, except for:

  • In mixed content nodes should not be indented, except for the first sibling, which should be indented if the parent is not in mixed content.
  • Text node children of elements that should have inlined text

- (BOOL) usesNewlines