public class XMLDocument extends Object implements IXMLUtilsConstants
XMLElement
class.
The in-memroy XML representation does not include any meta information such
as DOCTYPE
tags, processing instructions, or any commets. Such
tags are filtered out before the final in-memory representation of the XML
document is constructed. However, when this document is saved, these meta
information tags are re-inserted in the appropriate places so as to preserve
the original format of the document in all respects possible. Even white
spaces are preserved as far as possible.
This implementation uses an adhoc scanner/parser and does not rely on any third party libraries.
DOCTYPE, NEW_LINE, TOKEN_TYPE_BOUNDED, TOKEN_TYPE_COMMENT, TOKEN_TYPE_DOCTYPE, TOKEN_TYPE_META, TOKEN_TYPE_UNBOUNDED, TOKEN_TYPE_WHITESPACE
Constructor and Description |
---|
XMLDocument(File file)
Creates an instance of XMLDocument using the specified
File
object. |
Modifier and Type | Method and Description |
---|---|
String |
getDoctypeString()
Returns the DOCTYPE string associated with the first DOCTYPE element
present in this document.
|
XMLElement |
getRootElement()
Returns the root element for the given XML document.
|
XMLElement |
newCollapsedElement(String name)
A factory method used for the creation of new XML elements that can be
added to this XML document at a later stage.
|
XMLElement |
newElement(String name)
A factory method used for the creation of new XML elements that can be
added to this XML document at a later stage.
|
XMLElement |
newElement(String name,
String value)
A factory method used for the creation of new XML elements that can be
added to this XML document at a later stage.
|
XMLElement |
newElementFromXMLFragment(String xmlFragment)
A factory method used for the creation of new XML elements that can be
added to this XML document at a later stage.
|
void |
setIndentDepth(int spaces)
Sets the number of spaces used for denoting one indent level.
|
void |
setNoValueIndent()
Sets a flag that is used by the document to indent value tokens when
adding child elements that have value.
|
void |
setValueIndent()
Sets a flag that is used by the document to indent value tokens when
adding child elements that have value.
|
void |
store()
Stores the in-memory XML data to the file system.
|
void |
updatedDoctypeString(String newDoctypeString)
This methods provides a means to update the DOCTYPE element of the
document with a new value as supplied in the argument.
|
public XMLDocument(File file) throws Exception
File
object. No checking is done to ensure the availablity and readability of
the file passed in as the argument. It is expected that the caller has
completed such checks and taken the necessary backups before creating
this instance.file
- representing the XML document on file system.Exception
- in case an error occurse during the parsing of this
document.public XMLElement getRootElement()
public XMLElement newElement(String name) throws Exception
XMLElement
object is returned to the caller.
However, this newly created element is still not attached to the
document anywhere and it is the responsiblity of the caller to attach it
in the appropriate location.name
- the name of the new element to be createdException
- in case the creation of the new element fails due to any
reasonpublic XMLElement newCollapsedElement(String name) throws Exception
XMLElement
object is returned to the caller.
However, this newly created element is still not attached to the
document anywhere and it is the responsiblity of the caller to attach it
in the appropriate location. Further, the element returned from this
method is a collapsed element that is contained within a single bounded
token.name
- the name of the new element to be createdException
- in case the creation of the new element fails due to any
reasonpublic XMLElement newElementFromXMLFragment(String xmlFragment) throws Exception
XMLElement
object is returned to the caller.
However, this newly created element is still not attached to the
document anywhere and it is the responsiblity of the caller to attach it
in the appropriate location. Note that the supplied parameter
xmlFragement
must be a valid well-formed xml element.xmlFragment
- the xml fragment which will be parsed into an elementException
- in case the creation of the new element fails due to any
reasonpublic XMLElement newElement(String name, String value) throws Exception
XMLElement
object is returned to the caller.
However, this newly created element is still not attached to the
document anywhere and it is the responsiblity of the caller to attach it
in the appropriate location.name
- the name of the new element to be createdvalue
- the value of the new element to be createdException
- in case the creation of the new element fails due to any
reasonpublic void store() throws Exception
Exception
- If the save operation did not succeed.public void setIndentDepth(int spaces)
4
spaces. However, this can
be changed by calling this method anytime. This value comes into effect
only when any new element is added to the XML document.spaces
- the number of spaces used to denote one level of indentationpublic void setNoValueIndent()
public void setValueIndent()
setNoValueIndent
method, it can be reset back to its original state by calling this
method.public String getDoctypeString()
public void updatedDoctypeString(String newDoctypeString) throws Exception
newDoctypeString
- Exception
Copyright © 2010–2025 Open Identity Platform Community. All rights reserved.