|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.basedb.util.XMLUtil
public class XMLUtil
This class contains some useful methods for handling XML documents.
Nested Class Summary | |
---|---|
private static class |
XMLUtil.Validator
This class is used to handle callbacks from the XML parser. |
Field Summary | |
---|---|
private static Logger |
log
Log core events. |
private static String |
xmlParserClass
The parser class we are using. |
Constructor Summary | |
---|---|
XMLUtil()
|
Method Summary | |
---|---|
static Document |
createDom(String rootElement,
String systemId)
Create a new Document with root element and System id
declaration. |
static boolean |
getBooleanAttribute(Element el,
String attribute,
boolean defaultValue)
Get the value of an attribute as a boolean. |
static int |
getIntAttribute(Element el,
String attribute,
int defaultValue)
Get the value of an attribute as an integer. |
static Document |
getSchemaValidatedXML(InputStream in,
String filename,
String... schemaFiles)
Validate an XML input stream using XML schemas. |
static Document |
getSchemaValidatedXML(URL xmlFile,
String... schemaFiles)
Validate an XML file using XML schemas. |
static Document |
getValidatedXML(InputStream is,
URL dtdFile)
Deprecated. Use getValidatedXML(InputStream, URL, String) instead |
static Document |
getValidatedXML(InputStream is,
URL dtdFile,
String filename)
Validate an InputStream against a DTD file
and return it as a Document |
static Document |
getValidatedXml(String xml,
URL dtdFile)
|
static Document |
getValidatedXml(URL xmlFile,
URL dtdFile)
Load and validate an XML file against a DTD, and return it as a Document object. |
static Document |
getXml(String xml,
URL dtdFile,
boolean validate)
Parse a string containing XML, optionally validating it against a DTD, and return it as a Document object. |
static String |
toXml(Document dom)
Convert a Document to xml. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static final Logger log
private static final String xmlParserClass
Constructor Detail |
---|
public XMLUtil()
Method Detail |
---|
public static String toXml(Document dom)
Document
to xml. The encoding is set to UTF-8.
dom
- The document
public static Document createDom(String rootElement, String systemId)
Document
with root element and System id
declaration.
rootElement
- The name of the root element tagsystemId
- The system id in the DOCTYPE section
Document
objectpublic static Document getValidatedXML(InputStream is, URL dtdFile) throws JDOMException, IOException
getValidatedXML(InputStream, URL, String)
instead
JDOMException
IOException
public static Document getValidatedXml(URL xmlFile, URL dtdFile) throws JDOMException, 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-1
Document
object
JDOMException
- If validation of XML fails.
IOException
- If reading the input stream fails.public static Document getValidatedXml(String xml, URL dtdFile) throws JDOMException, IOException
JDOMException
IOException
getXml(String, URL, boolean)
public static Document getXml(String xml, URL dtdFile, boolean validate) throws JDOMException, 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 data
Document
object
JDOMException
- If validation of XML fails.
IOException
- If reading the string fails.public static Document getValidatedXML(InputStream is, URL dtdFile, String filename) throws JDOMException, 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 known
Document
object
JDOMException
- If validation of the XML fails.
IOException
- If reading the input stream fails.public static Document getSchemaValidatedXML(URL xmlFile, String... schemaFiles) throws JDOMException, 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 file
Document
object
JDOMException
- If validation of the XML fails
IOException
- If reading the input stream failspublic static Document getSchemaValidatedXML(InputStream in, String filename, String... schemaFiles) throws JDOMException, 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 file
Document
object
JDOMException
- If validation of the XML fails
IOException
- If reading the input stream failspublic static int getIntAttribute(Element el, String attribute, int defaultValue)
el
- The node element which contains the attributeattribute
- The name of the attributedefaultValue
- The default value to return
public static boolean getBooleanAttribute(Element el, String attribute, boolean defaultValue)
el
- The node element which contains the attributeattribute
- The name of the attributedefaultValue
- The default value to return
|
2.17.2: 2011-06-17 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |