public class XMLUtil
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
private static class |
XMLUtil.Validator
This class is used to handle callbacks from the XML parser.
|
Modifier and Type | Field and Description |
---|---|
private static org.slf4j.Logger |
log
Log core events.
|
private static java.lang.String |
xmlParserClass
The parser class we are using.
|
Constructor and Description |
---|
XMLUtil() |
Modifier and Type | Method and Description |
---|---|
static org.jdom.Document |
createDom(java.lang.String rootElement,
java.lang.String systemId)
Create a new
Document with root element and System id
declaration. |
static boolean |
getBooleanAttribute(org.jdom.Element el,
java.lang.String attribute,
boolean defaultValue)
Get the value of an attribute as a boolean.
|
static int |
getIntAttribute(org.jdom.Element el,
java.lang.String attribute,
int defaultValue)
Get the value of an attribute as an integer.
|
static org.jdom.Document |
getSchemaValidatedXML(java.io.InputStream in,
java.lang.String filename,
java.lang.String... schemaFiles)
Validate an XML input stream using XML schemas.
|
static org.jdom.Document |
getSchemaValidatedXML(java.net.URL xmlFile,
java.lang.String... schemaFiles)
Validate an XML file using XML schemas.
|
static org.jdom.Document |
getValidatedXML(java.io.InputStream is,
java.net.URL dtdFile,
java.lang.String filename)
Validate an
InputStream against a DTD file
and return it as a Document |
static org.jdom.Document |
getValidatedXml(java.lang.String xml,
java.net.URL dtdFile) |
static org.jdom.Document |
getValidatedXml(java.net.URL xmlFile,
java.net.URL dtdFile)
Load and validate an XML file against a DTD, and return it as a
Document object. |
static org.jdom.Document |
getXml(java.lang.String xml,
java.net.URL dtdFile,
boolean validate)
Parse a string containing XML, optionally validating it against a DTD,
and return it as a
Document object. |
static java.lang.String |
toXml(org.jdom.Document dom)
Convert a
Document to xml. |
private static final org.slf4j.Logger log
private static final java.lang.String xmlParserClass
public static java.lang.String toXml(org.jdom.Document dom)
Document
to xml. The encoding is set to UTF-8.dom
- The documentpublic static org.jdom.Document createDom(java.lang.String rootElement, java.lang.String systemId)
Document
with root element and System id
declaration.rootElement
- The name of the root element tagsystemId
- The system id in the DOCTYPE sectionDocument
objectpublic static org.jdom.Document getValidatedXml(java.net.URL xmlFile, java.net.URL dtdFile) throws org.jdom.JDOMException, java.io.IOException
Document
object. The path to the files should
be given as a URL, not a filesystem path. For a file on the classpath
it is easiest done by the Class.getResource(String)
method, ie.
XMLUtil.class.getResource("/net/sf/basedb/core/the-xml-file.xml")
.xmlFile
- The URL to the XML filedtdFile
- The URL to the DTD used for validation, the DTD must be encoded in ISO-8859-1Document
objectorg.jdom.JDOMException
- If validation of XML fails.java.io.IOException
- If reading the input stream fails.public static org.jdom.Document getValidatedXml(java.lang.String xml, java.net.URL dtdFile) throws org.jdom.JDOMException, java.io.IOException
org.jdom.JDOMException
java.io.IOException
getXml(String, URL, boolean)
public static org.jdom.Document getXml(java.lang.String xml, java.net.URL dtdFile, boolean validate) throws org.jdom.JDOMException, java.io.IOException
Document
object. The path to the DTD should
be given as a URL, not a filesystem path. For a file on the classpath
it is easiest done by the Class.getResource(String)
method, ie.
XMLUtil.class.getResource("/net/sf/basedb/core/the-dtd-file.dtd")
.xml
- The string containing the XMLdtdFile
- The URL to the DTD used for validation, the DTD must be encoded in ISO-8859-1validate
- TRUE to validate the xml dataDocument
objectorg.jdom.JDOMException
- If validation of XML fails.java.io.IOException
- If reading the string fails.public static org.jdom.Document getValidatedXML(java.io.InputStream is, java.net.URL dtdFile, java.lang.String filename) throws org.jdom.JDOMException, java.io.IOException
InputStream
against a DTD file
and return it as a Document
is
- The inputstream to the XMLdtdFile
- The URL to the DTD used for validation or null to not valdiate
against a DTD. The DTD must be encoded in ISO-8859-1filename
- The filename of the original XML data, used for error reporting only;
use null if the filename is not knownDocument
objectorg.jdom.JDOMException
- If validation of the XML fails.java.io.IOException
- If reading the input stream fails.public static org.jdom.Document getSchemaValidatedXML(java.net.URL xmlFile, java.lang.String... schemaFiles) throws org.jdom.JDOMException, java.io.IOException
xmlFile
- The URL pointing to the XML file to loadschemaFiles
- An array of schema file declarations. The array must
contain pairs of elements, the first one is the namespace name, and the
second element is the URL to the schema definition fileDocument
objectorg.jdom.JDOMException
- If validation of the XML failsjava.io.IOException
- If reading the input stream failspublic static org.jdom.Document getSchemaValidatedXML(java.io.InputStream in, java.lang.String filename, java.lang.String... schemaFiles) throws org.jdom.JDOMException, java.io.IOException
in
- The inputstream to the XMLfilename
- The filename of the original XML data, used for error reporting only;
use null if the filename is not knownschemaFiles
- An array of schema file declarations. The array must
contain pairs of elements, the first one is the namespace name, and the
second element is the URL to the schema definition fileDocument
objectorg.jdom.JDOMException
- If validation of the XML failsjava.io.IOException
- If reading the input stream failspublic static int getIntAttribute(org.jdom.Element el, java.lang.String attribute, int defaultValue)
el
- The node element which contains the attributeattribute
- The name of the attributedefaultValue
- The default value to returnpublic static boolean getBooleanAttribute(org.jdom.Element el, java.lang.String attribute, boolean defaultValue)
el
- The node element which contains the attributeattribute
- The name of the attributedefaultValue
- The default value to return