|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcmsc420.xml.XmlUtility
public class XmlUtility
Wrapper class for XML API validation and parsing methods. Shortcut methods for reading, writing, parsing, validating, and transforming XML files.
Method Summary | |
---|---|
static javax.xml.parsers.DocumentBuilder |
getDocumentBuilder()
Gets a DocumentBuilder from the DocumentBuilderFactory |
static javax.xml.transform.Transformer |
getTransformer()
Gets a Transformer from the TransformerFactory |
static boolean |
isValidXml(java.io.File file)
Checks if the file is valid XML (note: does not check it against a referenced schema) |
static org.w3c.dom.Document |
parse(java.io.File file)
Parses a given XML file and returns the DOM Document tree. |
static org.w3c.dom.Document |
parse(java.io.InputStream inputStream)
Parses a given XML input stream and returns the DOM Document tree. |
static void |
print(org.w3c.dom.Document document)
Prints a DOM Document tree to System.out |
static java.io.Reader |
read(org.w3c.dom.Document document)
Reads a DOM Document tree to a piped reader. |
static java.io.InputStream |
stream(org.w3c.dom.Document document)
Streams a DOM Document tree to a piped input stream. |
static void |
transform(org.w3c.dom.Document xmlDom,
java.io.File xsltFile,
java.io.File htmlFile)
Transforms a given XML Document with an XSLT file to an HTML file. |
static void |
transform(java.io.File xmlFile,
java.io.File xsltFile,
java.io.File htmlFile)
Transforms a given XML file with an XSLT file to an HTML file. |
static void |
transform(javax.xml.transform.Source xmlSource,
java.io.File xsltFile,
java.io.File htmlFile)
Transforms a given XML source with an XSLT file to an HTML file. |
static org.w3c.dom.Document |
validate(java.io.File xmlFile,
javax.xml.transform.Source schemaSource)
Validates an XML file against an XML schema. |
static org.w3c.dom.Document |
validateNoNamespace(java.io.File xmlFile)
Validates an input file against an internal schema. |
static org.w3c.dom.Document |
validateNoNamespace(java.io.InputStream xmlStream)
Validates an input stream against an internal schema. |
static void |
write(org.w3c.dom.Document document,
java.io.File outFile)
Writes a DOM Document tree to an XML file. |
static void |
write(org.w3c.dom.Document document,
java.io.OutputStream outputStream)
Writes a DOM Document tree to a given XML output stream. |
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static javax.xml.parsers.DocumentBuilder getDocumentBuilder() throws javax.xml.parsers.ParserConfigurationException
javax.xml.parsers.ParserConfigurationException
- a serious configuration errorpublic static javax.xml.transform.Transformer getTransformer() throws javax.xml.transform.TransformerConfigurationException
javax.xml.transform.TransformerConfigurationException
- a serious configuration errorpublic static boolean isValidXml(java.io.File file)
file
- checked if is a valid XML file
true
if the file is valid XML, false
otherwisepublic static org.w3c.dom.Document parse(java.io.File file) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
file
- XML file to be parsed
javax.xml.parsers.ParserConfigurationException
- a serious configuration error
org.xml.sax.SAXException
- encapsulates a SAX parsing error
java.io.IOException
- problem opening/reading the filepublic static org.w3c.dom.Document parse(java.io.InputStream inputStream) throws javax.xml.parsers.ParserConfigurationException, org.xml.sax.SAXException, java.io.IOException
inputStream
- XML stream to be parsed
javax.xml.parsers.ParserConfigurationException
- a serious configuration error
org.xml.sax.SAXException
- encapsulates a SAX parsing error
java.io.IOException
- problem reading the input streampublic static java.io.Reader read(org.w3c.dom.Document document) throws java.io.IOException, javax.xml.transform.TransformerException
document
- DOM Document tree
java.io.IOException
- problem reading the document
javax.xml.transform.TransformerException
- a problem during the transformation processpublic static java.io.InputStream stream(org.w3c.dom.Document document) throws java.io.IOException, javax.xml.transform.TransformerException
document
- DOM Document tree
java.io.IOException
- problem streaming the document
javax.xml.transform.TransformerException
- a problem during the transformation processpublic static void print(org.w3c.dom.Document document) throws javax.xml.transform.TransformerException
document
- DOM Document tree which represents an XML file
javax.xml.transform.TransformerException
- a problem during the transformation processpublic static void write(org.w3c.dom.Document document, java.io.File outFile) throws javax.xml.transform.TransformerException, java.io.FileNotFoundException
document
- DOM Document treeoutFile
- XML output file
javax.xml.transform.TransformerException
- a problem during the transformation process
java.io.FileNotFoundException
- output file is inaccessiblepublic static void write(org.w3c.dom.Document document, java.io.OutputStream outputStream) throws javax.xml.transform.TransformerException
document
- DOM Document treeoutputStream
- XML output stream
javax.xml.transform.TransformerException
- a problem during the transformation processpublic static void transform(java.io.File xmlFile, java.io.File xsltFile, java.io.File htmlFile) throws javax.xml.transform.TransformerException, java.io.FileNotFoundException
xmlFile
- XML input file to be transformedxsltFile
- XSLT file which determines how the XML is transformed to HTMLhtmlFile
- HTML output file
javax.xml.transform.TransformerException
- a problem during the transformation process
java.io.FileNotFoundException
- XML output file is inaccessiblepublic static void transform(org.w3c.dom.Document xmlDom, java.io.File xsltFile, java.io.File htmlFile) throws javax.xml.transform.TransformerException, java.io.FileNotFoundException
xmlDom
- XML input Document to be transformedxsltFile
- XSLT file which determines how the XML is transformed to HTMLhtmlFile
- HTML output file
javax.xml.transform.TransformerException
- a problem during the transformation process
java.io.FileNotFoundException
- XML output file is inaccessiblepublic static void transform(javax.xml.transform.Source xmlSource, java.io.File xsltFile, java.io.File htmlFile) throws javax.xml.transform.TransformerException, java.io.FileNotFoundException
xmlSource
- XML input source to be transformedxsltFile
- XSLT file which determines how the XML is transformed to HTMLhtmlFile
- HTML output file
javax.xml.transform.TransformerException
- a problem during the transformation process
java.io.FileNotFoundException
- XML output file is inaccessiblepublic static org.w3c.dom.Document validate(java.io.File xmlFile, javax.xml.transform.Source schemaSource) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
xmlFile
- XML file to be validatedschemaSource
- XML Schema source - can be created this way: Source
schemaSource = new StreamSource(new File(schemaFileName));
org.xml.sax.SAXException
- encapsulates a problem validating the document
java.io.IOException
- problem opening/reading the file
javax.xml.parsers.ParserConfigurationException
- a serious configuration errorpublic static org.w3c.dom.Document validateNoNamespace(java.io.File xmlFile) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
xmlFile
- XML file containing schema reference
org.xml.sax.SAXException
- encapsulates problem validating the XML document
java.io.IOException
- problem reading the XML file
javax.xml.parsers.ParserConfigurationException
- a serious configuration error
javax.naming.OperationNotSupportedException
public static org.w3c.dom.Document validateNoNamespace(java.io.InputStream xmlStream) throws org.xml.sax.SAXException, java.io.IOException, javax.xml.parsers.ParserConfigurationException
xmlStream
- XML input stream containing schema reference
org.xml.sax.SAXException
- encapsulates problem validating the XML document
java.io.IOException
- problem reading the XML input stream
javax.xml.parsers.ParserConfigurationException
- a serious configuration error
javax.naming.OperationNotSupportedException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |