public class XMLParser
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DTD_WEB_LOCATION
The (@link
XMLStore2 schema |
static java.lang.String |
SCHEMA_WEB_LOCATION
The application configuration schema
|
Constructor and Description |
---|
XMLParser() |
Modifier and Type | Method and Description |
---|---|
static javax.xml.parsers.DocumentBuilder |
createDocBuilder(javax.xml.parsers.DocumentBuilderFactory factory)
Create a XML document builder.
|
static javax.xml.parsers.DocumentBuilderFactory |
createFactory(java.lang.String schemaName)
Used to create a DOM document builder factory
|
protected void |
deleteNode(org.w3c.dom.Element parent,
java.lang.String name) |
static java.lang.String |
domToStr(org.w3c.dom.Document document)
Used to convert a DOM document to a string
|
static java.lang.String |
domToStrNoXMLProlog(org.w3c.dom.Document document)
Used to convert a DOM document to a string.
|
static java.lang.String |
encodeAttributeValue(java.lang.String value)
This is used to make sure a value can be written to a XML document by encoding the characters that should be XML entities.
|
static org.w3c.dom.Element |
firstChild(org.w3c.dom.Node parent)
Used to get the first XML element under a parent element
|
static java.lang.String |
fixXMl(java.lang.String result)
Used to fix XML characters in string
|
protected java.lang.String |
getAttribute(org.w3c.dom.Element node,
java.lang.String attributeName) |
protected org.w3c.dom.Element |
getElement(org.w3c.dom.Node parent,
java.lang.String name) |
protected org.w3c.dom.Element |
getFirstChildElement(org.w3c.dom.Node parent,
java.lang.String name) |
protected float |
getFloatFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a float from the XML
|
protected java.lang.Integer |
getIntegerFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a integer from the XML
|
protected org.w3c.dom.Element |
getLastChildElement(org.w3c.dom.Node parent,
java.lang.String name) |
protected java.lang.Long |
getLongFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a long from the XML
|
static javax.xml.validation.Schema |
getSchema(java.lang.String name)
Used to create a Schema that can be used to validate XML documents
|
protected java.lang.String |
getStringFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a string from the XML
|
protected java.lang.String |
getStringFromXMLOrNull(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a string from the XML, if it can't be found then return null
|
protected java.net.URL |
getURLFromXML(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a URL from the XML
|
protected java.net.URL |
getURLFromXMLOrNull(org.w3c.dom.Node parent,
java.lang.String path)
Used to read a URL; from the XML, if it can't be found then return null
|
static boolean |
hasNode(org.w3c.dom.Document document,
java.lang.String path)
Used to see if a XML document contains a node
|
static org.w3c.dom.Document |
parse(java.io.File file,
java.lang.String schemaName)
Used to convert a XML file to a XML document.
|
static org.w3c.dom.Document |
parse(java.io.InputStream is,
java.lang.String schemaName)
Used to convert a XML InputStream to a XML document.
|
static org.w3c.dom.Document |
parse(java.lang.String contents,
java.lang.String schemaName)
Used to convert a XML String to a XML document.
|
java.lang.String |
quoteXPathQuery(java.lang.String s)
Used to quote xpath queries
|
static java.util.List<org.w3c.dom.Element> |
selectChildNodes(org.w3c.dom.Node parent,
java.lang.String childName)
Used to get a list of children nodes under a parent XML node that match
a given name
|
static IterableNodeList |
selectNodeList(org.w3c.dom.Node contextNode,
java.lang.String path)
Used to get a list of XML nodes using a XPath path
|
static org.w3c.dom.Node |
selectSingleNode(org.w3c.dom.Node contextNode,
java.lang.String path)
Used to return a single XML node using a XPath path
|
static org.w3c.dom.Document |
strToDom(java.io.File file)
Used to convert a XML file to a DOM document
|
static org.w3c.dom.Document |
strToDom(java.lang.String str)
Used to convert a XML string to a DOM document
|
static org.w3c.dom.Document |
strToDom(java.lang.String str,
java.lang.String schemaName)
Used to convert a XML string to a DOM document
|
static void |
writeXML(java.io.File file,
org.w3c.dom.Document doc)
Used to write a XML document to a file
|
public static final java.lang.String DTD_WEB_LOCATION
XMLStore2
schemapublic static final java.lang.String SCHEMA_WEB_LOCATION
protected java.lang.Integer getIntegerFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the integerXMLParserException
- Thrown if their is a XML problemXMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.Long getLongFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the longXMLParserException
- Thrown if their is a XML problemXMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.String getStringFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the stringXMLParserException
- Thrown if their is a XML problemXMLParserNotFoundException
- Thrown if the value can't be readprotected java.lang.String getStringFromXMLOrNull(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the stringXMLParserException
- Thrown if their is a XML problemprotected java.net.URL getURLFromXML(org.w3c.dom.Node parent, java.lang.String path) throws java.net.MalformedURLException, XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the URLXMLParserException
- Thrown if their is a XML problemXMLParserNotFoundException
- Thrown if the value can't be readjava.net.MalformedURLException
protected java.net.URL getURLFromXMLOrNull(org.w3c.dom.Node parent, java.lang.String path) throws java.net.MalformedURLException, XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the URLXMLParserException
- Thrown if their is a XML problemjava.net.MalformedURLException
protected float getFloatFromXML(org.w3c.dom.Node parent, java.lang.String path) throws XMLParserException
parent
- The parent node it's the path is to be used frompath
- The xpath location of the floatXMLParserException
- Thrown if their is a XML problemXMLParserNotFoundException
- Thrown if the value can't be readpublic static org.w3c.dom.Document strToDom(java.lang.String str, java.lang.String schemaName) throws XMLParserException
str
- The string to convertschemaName
- the name of the schema, or null if one should not be usedXMLParserException
- Thrown if their is a parsing problempublic static org.w3c.dom.Document strToDom(java.lang.String str) throws XMLParserException
str
- The string to convertXMLParserException
- Thrown if their is a parsing problempublic static java.lang.String fixXMl(java.lang.String result)
result
- The XML to fixpublic static org.w3c.dom.Document strToDom(java.io.File file) throws XMLParserException, java.io.IOException
file
- the XML fileXMLParserException
- Thrown if their is a parsing problemjava.io.IOException
- Thrown if their is a problem reading the filepublic static java.lang.String domToStrNoXMLProlog(org.w3c.dom.Document document) throws XMLParserException
document
- The DOM documentXMLParserException
- Thrown if their is a parsing problempublic static java.lang.String domToStr(org.w3c.dom.Document document) throws XMLParserException
document
- The DOM documentXMLParserException
- Thrown if their is a parsing problemprotected org.w3c.dom.Element getFirstChildElement(org.w3c.dom.Node parent, java.lang.String name)
protected org.w3c.dom.Element getLastChildElement(org.w3c.dom.Node parent, java.lang.String name)
public static org.w3c.dom.Element firstChild(org.w3c.dom.Node parent)
parent
- The parent elementpublic static java.util.List<org.w3c.dom.Element> selectChildNodes(org.w3c.dom.Node parent, java.lang.String childName)
parent
- The parent namechildName
- The name of the children to returnpublic static IterableNodeList selectNodeList(org.w3c.dom.Node contextNode, java.lang.String path) throws XMLParserException
contextNode
- The context that the path should be used withpath
- The XPath pathXMLParserException
- Thrown if their is a XML problempublic static org.w3c.dom.Node selectSingleNode(org.w3c.dom.Node contextNode, java.lang.String path) throws XMLParserException
contextNode
- The context that the path should be used withpath
- The XPath pathXMLParserException
- Thrown if their is a XML problempublic static javax.xml.parsers.DocumentBuilder createDocBuilder(javax.xml.parsers.DocumentBuilderFactory factory) throws javax.xml.parsers.ParserConfigurationException
factory
- The document builder factoryjavax.xml.parsers.ParserConfigurationException
- Thrown if their are any problemspublic static org.w3c.dom.Document parse(java.lang.String contents, java.lang.String schemaName) throws XMLParserException
contents
- The XML StringschemaName
- The schema name, or null if validation is not requiredXMLParserException
- Thrown if their was a problem converting the string to a documentpublic static org.w3c.dom.Document parse(java.io.InputStream is, java.lang.String schemaName) throws XMLParserException
is
- The XML InputStreamschemaName
- The schema name, or null if validation is not requiredXMLParserException
- Thrown if their was a problem converting the string to a documentpublic static javax.xml.parsers.DocumentBuilderFactory createFactory(java.lang.String schemaName)
schemaName
- The schema name, or null if one should not be usedpublic static org.w3c.dom.Document parse(java.io.File file, java.lang.String schemaName) throws XMLParserException
file
- The XML fileschemaName
- The schema name, or null if validation is not requiredXMLParserException
- Thrown if their was a problem converting the file to a documentpublic static javax.xml.validation.Schema getSchema(java.lang.String name) throws XMLParserException
name
- The name of the schemaXMLParserException
- Thrown if their are any problemspublic static java.lang.String encodeAttributeValue(java.lang.String value)
value
- The value to encodepublic static void writeXML(java.io.File file, org.w3c.dom.Document doc) throws java.io.IOException
file
- The file to writedoc
- The XML contentsjava.io.IOException
- Thrown if thier is aproblem writing the filepublic java.lang.String quoteXPathQuery(java.lang.String s)
s
- The queryprotected java.lang.String getAttribute(org.w3c.dom.Element node, java.lang.String attributeName) throws XMLParserNotFoundException
XMLParserNotFoundException
protected void deleteNode(org.w3c.dom.Element parent, java.lang.String name)
protected org.w3c.dom.Element getElement(org.w3c.dom.Node parent, java.lang.String name)
public static boolean hasNode(org.w3c.dom.Document document, java.lang.String path) throws XMLParserException
document
- The XMLpath
- The node to look for ( via a xpath path)XMLParserException
- Thrown if their is a parser problem