Package org.dom4j.io
Class SAXModifier
- java.lang.Object
 - 
- org.dom4j.io.SAXModifier
 
 
- 
public class SAXModifier extends Object
The SAXModifier reads, modifies and writes XML documents using SAX.Registered
ElementModifierobjects can provide modifications to (part of) the xml tree, while the document is still being processed. This makes it possible to change large xml documents without having them in memory.The modified document is written when the
XMLWriteris specified. 
- 
- 
Constructor Summary
Constructors Constructor Description SAXModifier()Creates a new modifier.SAXModifier(boolean pruneElements)Creates a new modifier.SAXModifier(XMLReader xmlReader)Creates a new modifier that will the specifiedXMLReaderto parse the source.SAXModifier(XMLReader xmlReader, boolean pruneElements)Creates a new modifier that will the specifiedXMLReaderto parse the source. 
- 
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddModifier(String path, ElementModifier modifier)Adds theElementModifierto be called when the specified element path is encounted while parsing the source.DocumentFactorygetDocumentFactory()Get theDocumentFactoryused to create the DOM4J document structureXMLWritergetXMLWriter()Returns the currentXMLWriter.booleanisPruneElements()Returns true when xml elements are not kept in memory while parsing.Documentmodify(File source)Documentmodify(InputStream source)Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX.Documentmodify(InputStream source, String systemId)Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX.Documentmodify(Reader source)Documentmodify(Reader source, String systemId)Documentmodify(String source)Reads a Document from the given URL or filename and writes it to the specifiedXMLWriterusing SAX.Documentmodify(URL source)Documentmodify(InputSource source)Reads a Document from the givenInputSourceand writes it to the specifiedXMLWriterusing SAX.voidremoveModifier(String path)Removes theElementModifierfrom the event based processor, for the specified element path.voidresetModifiers()Removes all registeredElementModifierinstances from the event based processor.voidsetDocumentFactory(DocumentFactory factory)Sets theDocumentFactoryused to create the DOM4J document tree.voidsetXMLWriter(XMLWriter writer)Sets theXMLWriterused to write the modified document. 
 - 
 
- 
- 
Constructor Detail
- 
SAXModifier
public SAXModifier()
Creates a new modifier.
The XMLReader to parse the source will be created via the org.xml.sax.driver system property or JAXP if the system property is not set. 
- 
SAXModifier
public SAXModifier(boolean pruneElements)
Creates a new modifier.
The XMLReader to parse the source will be created via the org.xml.sax.driver system property or JAXP if the system property is not set.- Parameters:
 pruneElements- Set to true when the modified document must NOT be kept in memory.
 
- 
SAXModifier
public SAXModifier(XMLReader xmlReader)
Creates a new modifier that will the specifiedXMLReaderto parse the source.- Parameters:
 xmlReader- The XMLReader to use
 
 - 
 
- 
Method Detail
- 
modify
public Document modify(File source) throws DocumentException
Reads a Document from the givenFileand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is theFileto read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(InputSource source) throws DocumentException
Reads a Document from the givenInputSourceand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is theorg.xml.sax.InputSourceto read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(InputStream source) throws DocumentException
Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is thejava.io.InputStreamto read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(InputStream source, String systemId) throws DocumentException
Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is thejava.io.InputStreamto read from.systemId- DOCUMENT ME!- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(Reader source) throws DocumentException
Reads a Document from the givenReaderand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is thejava.io.Readerto read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(Reader source, String systemId) throws DocumentException
Reads a Document from the givenReaderand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is thejava.io.Readerto read from.systemId- DOCUMENT ME!- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(URL source) throws DocumentException
Reads a Document from the givenURLand writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is thejava.net.URLto read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
modify
public Document modify(String source) throws DocumentException
Reads a Document from the given URL or filename and writes it to the specifiedXMLWriterusing SAX. RegisteredElementModifierobjects are invoked on the fly.- Parameters:
 source- is the URL or filename to read from.- Returns:
 - the newly created Document instance
 - Throws:
 DocumentException- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
 
- 
addModifier
public void addModifier(String path, ElementModifier modifier)
Adds theElementModifierto be called when the specified element path is encounted while parsing the source.- Parameters:
 path- The element path to be handledmodifier- TheElementModifierto be called by the event based processor.
 
- 
resetModifiers
public void resetModifiers()
Removes all registeredElementModifierinstances from the event based processor. 
- 
removeModifier
public void removeModifier(String path)
Removes theElementModifierfrom the event based processor, for the specified element path.- Parameters:
 path- The path to remove theElementModifierfor.
 
- 
getDocumentFactory
public DocumentFactory getDocumentFactory()
Get theDocumentFactoryused to create the DOM4J document structure- Returns:
 DocumentFactorythat will be used
 
- 
setDocumentFactory
public void setDocumentFactory(DocumentFactory factory)
Sets theDocumentFactoryused to create the DOM4J document tree.- Parameters:
 factory-DocumentFactoryto be used
 
- 
setXMLWriter
public void setXMLWriter(XMLWriter writer)
Sets theXMLWriterused to write the modified document.- Parameters:
 writer- The writer to use.
 
- 
isPruneElements
public boolean isPruneElements()
Returns true when xml elements are not kept in memory while parsing. TheDocumentreturned by the modify methods will be null.- Returns:
 - Returns the pruneElements.
 
 
 - 
 
 -