@NotThreadSafe public final class XMLDocument extends Object implements XMLElement.Factory
Instances of this class are not thread safe.
Modifier and Type | Class and Description |
---|---|
static class |
XMLDocument.ElementReader
Element reader.
|
static class |
XMLDocument.ParseException
Parse exception.
|
static interface |
XMLDocument.PIHandler
Processing instruction handler.
|
Constructor and Description |
---|
XMLDocument()
Constructs an instance.
|
XMLDocument(String name)
Constructs an instance.
|
XMLDocument(XMLElement rootElement)
Constructs an instance.
|
Modifier and Type | Method and Description |
---|---|
XMLElement |
createXMLElement(String name)
Creates a new element.
|
XMLElement.Factory |
getElementFactory()
Gets the element factory.
|
XMLElement |
getRootElement()
Gets the root element.
|
static XMLDocument |
load(File file)
Loads an XML document from a file.
|
static XMLDocument |
load(URL url,
Optional<String> encoding)
Loads an XML document from a URL.
|
XMLElement |
newXMLElement(String name)
Returns a new element.
|
XMLElement |
parse(File file,
Optional<String> encoding)
Parses XML from a file.
|
XMLElement |
parse(InputStream inputStream,
Optional<String> encoding)
Parses XML from an input stream.
|
XMLElement |
parse(Reader reader)
Parses XML from a reader.
|
XMLElement |
parse(String string)
Parses XML from a string.
|
XMLElement |
parse(URL url,
Optional<String> encoding)
Parses XML from an URL.
|
void |
setDefaultHandler(Optional<XMLElement.Handler> handler)
Sets the default handler.
|
void |
setDocTypeStrings(Optional<String> publicString,
Optional<String> systemString)
Sets the document type strings.
|
void |
setDocTypeStrings(String[] strings)
Sets the document type strings.
|
void |
setElementFactory(XMLElement.Factory elementFactory)
Sets the element factory.
|
void |
setElementHandler(String elementPath,
Optional<XMLElement.Handler> handler)
Sets an element handler.
|
void |
setPIHandler(Optional<XMLDocument.PIHandler> piHandler)
Sets the processing instruction handler.
|
void |
setRootElement(Optional<XMLElement> rootElement)
Sets the root element.
|
void |
setRootElement(String name)
Sets the root element.
|
void |
setRootHandler(Optional<XMLElement.Handler> handler)
Sets the root handler.
|
void |
setValidating(boolean validating)
Sets the validating indicator.
|
void |
setXMLReader(Optional<XMLReader> xmlReader)
Sets the XML reader.
|
String |
toString() |
String |
toXML(Optional<String> encoding,
boolean indented)
Returns this as a XML string.
|
void |
toXML(Optional<String> encoding,
boolean indented,
Appendable destination)
Converts this to XML.
|
public XMLDocument()
public XMLDocument(@Nonnull String name)
name
- The root element's name.public XMLDocument(@Nonnull XMLElement rootElement)
rootElement
- The root element.@Nullable @CheckReturnValue public static XMLDocument load(@Nonnull File file)
file
- The file.@Nullable @CheckReturnValue public static XMLDocument load(@Nonnull URL url, @Nonnull Optional<String> encoding)
url
- The URL.encoding
- The optional character encoding name.@Nonnull @CheckReturnValue public XMLElement createXMLElement(@Nonnull String name)
name
- The element's name.@Nonnull @CheckReturnValue public XMLElement.Factory getElementFactory()
@Nonnull @CheckReturnValue public XMLElement getRootElement()
@Nonnull @CheckReturnValue public XMLElement newXMLElement(@Nonnull String name)
newXMLElement
in interface XMLElement.Factory
name
- The element's name.@Nonnull public XMLElement parse(@Nonnull Reader reader) throws XMLDocument.ParseException
reader
- A reader for the XML text.XMLDocument.ParseException
- When appropriate.@Nonnull public XMLElement parse(@Nonnull String string) throws XMLDocument.ParseException
string
- The XML string.XMLDocument.ParseException
- When appropriate.@Nonnull public XMLElement parse(@Nonnull File file, @Nonnull Optional<String> encoding) throws XMLDocument.ParseException
file
- The XML file.encoding
- The optional character encoding name.XMLDocument.ParseException
- When appropriate.@Nonnull public XMLElement parse(@Nonnull InputStream inputStream, @Nonnull Optional<String> encoding) throws XMLDocument.ParseException
inputStream
- An input stream for the XML text.encoding
- The optional character encoding name.XMLDocument.ParseException
- When appropriate.@Nonnull public XMLElement parse(@Nonnull URL url, @Nonnull Optional<String> encoding) throws XMLDocument.ParseException
url
- The URL of the XML text.encoding
- The character encoding name (may be empty).XMLDocument.ParseException
- When appropriate.public void setDefaultHandler(@Nonnull Optional<XMLElement.Handler> handler)
handler
- The default handler.public void setDocTypeStrings(@Nonnull String[] strings)
strings
- An array holding the public and system strings.public void setDocTypeStrings(@Nonnull Optional<String> publicString, @Nonnull Optional<String> systemString)
publicString
- The optional public string.systemString
- The optional system string.public void setElementFactory(@Nonnull XMLElement.Factory elementFactory)
elementFactory
- The element factory.public void setElementHandler(@Nonnull String elementPath, @Nonnull Optional<XMLElement.Handler> handler)
elementPath
- The element path.handler
- The element handler (empty means remove).public void setPIHandler(@Nonnull Optional<XMLDocument.PIHandler> piHandler)
piHandler
- The optional processing instruction handler.public void setRootElement(@Nonnull Optional<XMLElement> rootElement)
rootElement
- The root element.public void setRootElement(@Nonnull String name)
name
- The root element's name.public void setRootHandler(@Nonnull Optional<XMLElement.Handler> handler)
handler
- The optional root handler.public void setValidating(boolean validating)
validating
- The validating indicator.public void setXMLReader(@Nonnull Optional<XMLReader> xmlReader)
xmlReader
- The optional XML reader.public String toString()
toString
in class Object
@Nonnull @CheckReturnValue public String toXML(@Nonnull Optional<String> encoding, boolean indented)
encoding
- The optional encoding identification for the XML header.indented
- True requests indented output.public void toXML(@Nonnull Optional<String> encoding, boolean indented, @Nonnull Appendable destination) throws IOException
encoding
- The optional encoding identification for the XML header.indented
- True requests indented output.destination
- The destination.IOException
- From the destination.Copyright © 2003-2019 Serge Brisson. All Rights Reserved.