|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jwo.utils.xml.DOMProcessor
public class DOMProcessor
Handles DOM processing allowing the reading and writing of hierarchical structures as XML files. Uses the Document Object Model (DOM) to store the tree of nodes, therefore not suitable for very large structures. For reading very large structures represented as XML, use SAXProcessor instead.
Constructor Summary | |
---|---|
DOMProcessor()
Creates a new empty DOM ready for processing. |
|
DOMProcessor(Document dom)
Wraps the given DOM in this processor allowing it to be written as an XML file, or appended with new nodes. |
|
DOMProcessor(InputStream inStream)
Reads XML from the given input stream and constructs a DOM from it. |
|
DOMProcessor(String fileName)
Reads and the given XML file and constructs a DOM from it. |
Method Summary | |
---|---|
void |
addAttribute(String name,
String value,
Node node)
Adds the given attribute to the given node. |
void |
addComment(String comment)
Adds the given comment to the root of the DOM. |
void |
addComment(String comment,
Node node)
Adds the given comment to the given node. |
Node |
addElement(String name)
Adds a new element to the root of the DOM. |
Node |
addElement(String name,
Node existingElement)
Adds a new element to the given one within the DOM. |
Node |
addElement(String name,
String text,
Node existingElement)
Adds a new element to the given one within the DOM. |
void |
addText(String text,
Node node)
Adds text as the child of the given node. |
String[] |
getAttributes(String attributeName)
Searches the entire DOM for a given attribute and returns the value associated with it. |
String[] |
getAttributes(String attributeName,
Node node)
Searches the given node and its children for a given attribute and returns the value associated with it. |
Node[] |
getElements(String name)
Returns a list of the DOM elements with the given name. |
Node[] |
getElements(String name,
Node node)
Returns a list of the DOM elements with the given name that are nested within the given node. |
String |
getNodeAttribute(String attributeName,
Node node)
Searches the given node for a given attribute and returns the value associated with it. |
Node |
getNodeElement(String name,
Node node)
Returns a DOM element with the given name that is the child of the given node. |
Node[] |
getNodeElements(String name,
Node node)
Returns the DOM elements with the given name that are the children of the given node. |
String |
getNodeText(Node node)
Searches for a given node and returns text associated with it. |
String[] |
getText(Node node)
Returns any text associated found in the given node or its children. |
String[] |
getText(String elementName)
Searches the entire DOM for a given element and returns text associated with it. |
String[] |
getText(String elementName,
Node node)
Searches for a given element and returns text associated with it. |
boolean |
isEmpty()
Reports whether we have an empty DOM. |
boolean |
readXML(InputStream inStream)
Reads the XML from the given input stream and converts it into a DOM. |
boolean |
readXML(String fileName)
Reads the given XML file and converts it into a DOM. |
void |
renameElement(Node existingElement,
String newName)
Renames the given element with the given new name. |
boolean |
writeXML()
Displays the DOM stored within this class as an XML file with default document settings on standard output. |
boolean |
writeXML(OutputStream outStream)
Converts the DOM stored within this class into an XML file with default document settings. |
boolean |
writeXML(OutputStream outStream,
String version,
String encoding,
Boolean standalone)
Converts the DOM stored within this class into an XML file with the given document settings. |
boolean |
writeXML(String fileName)
Converts the DOM stored within this class into an XML file with default document settings. |
boolean |
writeXML(String version,
String encoding,
Boolean standalone)
Displays the DOM stored within this class as an XML file with the given document settings on standard output. |
boolean |
writeXML(String fileName,
String version,
String encoding,
Boolean standalone)
Converts the DOM stored within this class into an XML file with the given document settings. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public DOMProcessor()
public DOMProcessor(Document dom)
dom
- Document Object Model to use in processor.public DOMProcessor(String fileName)
fileName
- Name of XML file to read.public DOMProcessor(InputStream inStream)
inStream
- Stream from which to read XML.Method Detail |
---|
public boolean isEmpty()
public Node addElement(String name)
name
- Name of the new element
public Node addElement(String name, Node existingElement)
name
- Name of the new elementexistingElement
- Element onto which the new element should be attached.
public Node addElement(String name, String text, Node existingElement)
name
- Name of the new elementtext
- Text to attach to element or null if none required.existingElement
- Element onto which the new element should be attached.
public void renameElement(Node existingElement, String newName)
existingElement
- Element to rename.newName
- New name to give element.public void addAttribute(String name, String value, Node node)
name
- Attribute name.value
- Attribute value.node
- Element to attach attribute.public void addComment(String comment)
comment
- Comment text.public void addComment(String comment, Node node)
comment
- Comment text.node
- Element to attach comment.public void addText(String text, Node node)
text
- Text to add to node.node
- Element to attach text.public String[] getText(String elementName)
elementName
- Element to search for.
public String[] getText(Node node)
getText(null,node)
.
If more than one element containing text exists, multiple text values
are returned.
node
- Node from which to start search.
public String[] getText(String elementName, Node node)
elementName
- Element to search for. If elementName is null, search
will be for all text contained within the given node.node
- Node from which to start search.
public String getNodeText(Node node)
node
- Node to search.
public String[] getAttributes(String attributeName)
attributeName
- Attribute to search for.
public String[] getAttributes(String attributeName, Node node)
attributeName
- Attribute to search for.node
- Node from which to start search.
public String getNodeAttribute(String attributeName, Node node)
attributeName
- Attribute to search for.node
- Node from which to start search.
public Node[] getElements(String name)
name
- Element name to search for.
public Node[] getElements(String name, Node node)
getNodeElements
and
recursively search for children of returned nodes.
name
- Element name to search for.node
- Node from which to start search.
public Node getNodeElement(String name, Node node)
getNodeElements()
this method only
returns the first matched child of the given node.
name
- Element name to search for.node
- Node from which to examine children.
public Node[] getNodeElements(String name, Node node)
name
- Element name to search for.node
- Node from which to examine children.
public boolean readXML(String fileName)
fileName
- Name of XML file to convert.
public boolean readXML(InputStream inStream)
inStream
- Input stream containing XML to convert.
public boolean writeXML()
public boolean writeXML(String version, String encoding, Boolean standalone)
version
- XML version, or null if default ('1.0') is to be used.encoding
- XML encoding, or null if encoding is not to be specified.standalone
- XML stand-alone status of XML file or null if not to be specified.
public boolean writeXML(String fileName)
fileName
- Name of file to contain the XML.
public boolean writeXML(OutputStream outStream)
outStream
- Output stream representing file to contain the XML.
public boolean writeXML(String fileName, String version, String encoding, Boolean standalone)
fileName
- Name of file to contain the XML.version
- XML version, or null if default ('1.0') is to be used.encoding
- XML encoding, or null if encoding is not to be specified.standalone
- XML stand-alone status of XML file or null if not to be specified.
public boolean writeXML(OutputStream outStream, String version, String encoding, Boolean standalone)
outStream
- Output stream representing file to contain the XML.version
- XML version, or null if default ('1.0') is to be used.encoding
- XML encoding, or null if encoding is not to be specified.standalone
- XML stand-alone status of XML file or null if not to be specified.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |