Class SAXModifier
java.lang.Object
org.dom4j.io.SAXModifier
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.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate HashMap<String, ElementModifier> private SAXModifyReaderprivate booleanprivate XMLReaderprivate XMLWriter -
Constructor Summary
ConstructorsConstructorDescriptionCreates 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
Modifier and TypeMethodDescriptionvoidaddModifier(String path, ElementModifier modifier) Adds theElementModifierto be called when the specified element path is encounted while parsing the source.Get theDocumentFactoryused to create the DOM4J document structureprivate SAXModifyReaderprivate XMLReaderReturns the currentXMLWriter.private SAXReaderbooleanReturns true when xml elements are not kept in memory while parsing.modify(InputStream source) Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX.modify(InputStream source, String systemId) Reads a Document from the givenInputStreamand writes it to the specifiedXMLWriterusing SAX.Reads a Document from the given URL or filename and writes it to the specifiedXMLWriterusing SAX.modify(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.voidRemoves 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.
-
Field Details
-
xmlWriter
-
xmlReader
-
pruneElements
private boolean pruneElements -
modifyReader
-
modifiers
-
-
Constructor Details
-
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
-
SAXModifier
-
-
Method Details
-
modify
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
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
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
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
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
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
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
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
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
Removes theElementModifierfrom the event based processor, for the specified element path.- Parameters:
path- The path to remove theElementModifierfor.
-
getDocumentFactory
Get theDocumentFactoryused to create the DOM4J document structure- Returns:
DocumentFactorythat will be used
-
setDocumentFactory
Sets theDocumentFactoryused to create the DOM4J document tree.- Parameters:
factory-DocumentFactoryto be used
-
getXMLWriter
-
setXMLWriter
-
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.
-
installModifyReader
- Throws:
DocumentException
-
getXMLReader
- Throws:
SAXException
-
getSAXModifyReader
-