Package org.dom4j.io
Class SAXModifier
- java.lang.Object
-
- org.dom4j.io.SAXModifier
-
public class SAXModifier extends java.lang.Object
The SAXModifier reads, modifies and writes XML documents using SAX.Registered
ElementModifier
objects 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
XMLWriter
is specified.
-
-
Constructor Summary
Constructors Constructor Description SAXModifier()
Creates a new modifier.SAXModifier(boolean pruneElements)
Creates a new modifier.SAXModifier(org.xml.sax.XMLReader xmlReader)
Creates a new modifier that will the specifiedXMLReader
to parse the source.SAXModifier(org.xml.sax.XMLReader xmlReader, boolean pruneElements)
Creates a new modifier that will the specifiedXMLReader
to parse the source.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addModifier(java.lang.String path, ElementModifier modifier)
Adds theElementModifier
to be called when the specified element path is encounted while parsing the source.DocumentFactory
getDocumentFactory()
Get theDocumentFactory
used to create the DOM4J document structureXMLWriter
getXMLWriter()
Returns the currentXMLWriter
.boolean
isPruneElements()
Returns true when xml elements are not kept in memory while parsing.Document
modify(java.io.File source)
Reads a Document from the givenFile
and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.io.InputStream source)
Reads a Document from the givenInputStream
and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.io.InputStream source, java.lang.String systemId)
Reads a Document from the givenInputStream
and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.io.Reader source)
Reads a Document from the givenReader
and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.io.Reader source, java.lang.String systemId)
Reads a Document from the givenReader
and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.lang.String source)
Reads a Document from the given URL or filename and writes it to the specifiedXMLWriter
using SAX.Document
modify(java.net.URL source)
Reads a Document from the givenURL
and writes it to the specifiedXMLWriter
using SAX.Document
modify(org.xml.sax.InputSource source)
Reads a Document from the givenInputSource
and writes it to the specifiedXMLWriter
using SAX.void
removeModifier(java.lang.String path)
Removes theElementModifier
from the event based processor, for the specified element path.void
resetModifiers()
Removes all registeredElementModifier
instances from the event based processor.void
setDocumentFactory(DocumentFactory factory)
Sets theDocumentFactory
used to create the DOM4J document tree.void
setXMLWriter(XMLWriter writer)
Sets theXMLWriter
used 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(org.xml.sax.XMLReader xmlReader)
Creates a new modifier that will the specifiedXMLReader
to parse the source.- Parameters:
xmlReader
- The XMLReader to use
-
SAXModifier
public SAXModifier(org.xml.sax.XMLReader xmlReader, boolean pruneElements)
Creates a new modifier that will the specifiedXMLReader
to parse the source.- Parameters:
xmlReader
- The XMLReader to usepruneElements
- Set to true when the modified document must NOT be kept in memory.
-
-
Method Detail
-
modify
public Document modify(java.io.File source) throws DocumentException
Reads a Document from the givenFile
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is theFile
to read from.- Returns:
- the newly created Document instance
- Throws:
DocumentException
- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
-
modify
public Document modify(org.xml.sax.InputSource source) throws DocumentException
Reads a Document from the givenInputSource
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is theorg.xml.sax.InputSource
to read from.- Returns:
- the newly created Document instance
- Throws:
DocumentException
- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
-
modify
public Document modify(java.io.InputStream source) throws DocumentException
Reads a Document from the givenInputStream
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is thejava.io.InputStream
to read from.- Returns:
- the newly created Document instance
- Throws:
DocumentException
- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
-
modify
public Document modify(java.io.InputStream source, java.lang.String systemId) throws DocumentException
Reads a Document from the givenInputStream
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is thejava.io.InputStream
to 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(java.io.Reader source) throws DocumentException
Reads a Document from the givenReader
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is thejava.io.Reader
to read from.- Returns:
- the newly created Document instance
- Throws:
DocumentException
- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
-
modify
public Document modify(java.io.Reader source, java.lang.String systemId) throws DocumentException
Reads a Document from the givenReader
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is thejava.io.Reader
to 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(java.net.URL source) throws DocumentException
Reads a Document from the givenURL
and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects are invoked on the fly.- Parameters:
source
- is thejava.net.URL
to read from.- Returns:
- the newly created Document instance
- Throws:
DocumentException
- DocumentException org.dom4j.DocumentException} if an error occurs during parsing.
-
modify
public Document modify(java.lang.String source) throws DocumentException
Reads a Document from the given URL or filename and writes it to the specifiedXMLWriter
using SAX. RegisteredElementModifier
objects 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(java.lang.String path, ElementModifier modifier)
Adds theElementModifier
to be called when the specified element path is encounted while parsing the source.- Parameters:
path
- The element path to be handledmodifier
- TheElementModifier
to be called by the event based processor.
-
resetModifiers
public void resetModifiers()
Removes all registeredElementModifier
instances from the event based processor.
-
removeModifier
public void removeModifier(java.lang.String path)
Removes theElementModifier
from the event based processor, for the specified element path.- Parameters:
path
- The path to remove theElementModifier
for.
-
getDocumentFactory
public DocumentFactory getDocumentFactory()
Get theDocumentFactory
used to create the DOM4J document structure- Returns:
DocumentFactory
that will be used
-
setDocumentFactory
public void setDocumentFactory(DocumentFactory factory)
Sets theDocumentFactory
used to create the DOM4J document tree.- Parameters:
factory
-DocumentFactory
to be used
-
setXMLWriter
public void setXMLWriter(XMLWriter writer)
Sets theXMLWriter
used 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. TheDocument
returned by the modify methods will be null.- Returns:
- Returns the pruneElements.
-
-