Package com.tangosol.run.xml
Class SaxParser
java.lang.Object
com.tangosol.util.Base
com.tangosol.run.xml.SaxParser
A simple XML parser. The public interface consists of nearly identical
methods: parseXml(...) which produce a tree of SimpleElement objects
- Author:
- gg 2000.10.23
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected class
An inner class Error Handler that is registered in parser that performs validation.Nested classes/interfaces inherited from class com.tangosol.util.Base
Base.LoggingWriter
-
Field Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected static Parser
Get an instance of non-validating SAX parser.protected XmlElement
instantiateRoot
(String sRoot) Instantiate an XmlElement implementation for a root element.static void
Unit test: create a simple parser, parse and output the result.parseXml
(InputStream input) Parse the specified InputStream into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments).Parse the specified Reader into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments).Parse the specified String into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments).parseXml
(String sXml, XmlElement elRoot) Parse the specified String into a tree of XmlElement objects (same as above) having the specified [empty] XmlElement a root.parseXml
(InputSource input) Parse the specified InputSource into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments).protected XmlElement
parseXml
(InputSource input, XmlElement xmlRoot) Actual implementation...protected Source[]
resolveSchemaSources
(List<String> listUri) For a given set of XSD URIs, return theSource
s to be used by the XML parser to validate an XML document.void
validateXsd
(String sXml, XmlDocument xml) XSD aware parsing routine; if XML contains an XSD reference to a schemeLocation/noNamespaceSchemaLocation then parse XML using provided XSD for validation.Methods inherited from class com.tangosol.util.Base
azzert, azzert, azzert, azzertFailed, breakLines, breakLines, capitalize, checkNotEmpty, checkNotNull, checkRange, computeSafeWaitTime, decimalValue, dup, dup, ensureBigDecimal, ensureClassLoader, ensureRuntimeException, ensureRuntimeException, equals, equalsDeep, err, err, err, err, err, escape, formatDateTime, getCallerStackFrame, getCommonMonitor, getCommonMonitor, getCommonMonitor, getContextClassLoader, getContextClassLoader, getDeepMessage, getErr, getLastSafeTimeMillis, getLog, getMaxDecDigits, getMaxHexDigits, getOriginalException, getOut, getProcessRandom, getRandom, getRandomBinary, getRandomBinary, getRandomString, getSafeTimeMillis, getStackFrame, getStackFrames, getStackTrace, getStackTrace, getStackTrace, getThreadFactory, getTimeZone, getUpTimeMillis, hashCode, hexValue, indentString, indentString, isDecimal, isHex, isLogEcho, isOctal, log, log, log, log, log, makeInteger, makeLong, makeThread, mergeArray, mergeBooleanArray, mergeByteArray, mergeCharArray, mergeDoubleArray, mergeFloatArray, mergeIntArray, mergeLongArray, mod, mod, octalValue, out, out, out, out, out, pad, parseBandwidth, parseBandwidth, parseDelimitedString, parseHex, parseHex, parseMemorySize, parseMemorySize, parsePercentage, parseTime, parseTime, parseTimeNanos, parseTimeNanos, printStackTrace, randomize, randomize, randomize, randomize, read, read, read, read, read, read, read, replace, setErr, setLog, setLogEcho, setOut, sleep, toBandwidthString, toBandwidthString, toCharEscape, toCrc, toCrc, toCrc, toCrc, toCrc, toDecString, toDelimitedString, toDelimitedString, toDelimitedString, toDelimitedString, toHex, toHex, toHexDump, toHexEscape, toHexEscape, toHexEscape, toHexEscape, toHexString, toMemorySizeString, toMemorySizeString, toQuotedCharEscape, toQuotedStringEscape, toSqlString, toString, toString, toStringEscape, toUnicodeEscape, trace, trace, trace, trace, trace, trace, trace, trace, trace, truncateString, truncateString, wait
-
Constructor Details
-
SaxParser
public SaxParser()Construct a SaxParser. -
SaxParser
public SaxParser(boolean fAllowComments) Construct a SaxParser.- Parameters:
fAllowComments
- if true, the resulting tree may contain the XMLValue nodes that contain comments; otherwize all comments are ignored
-
-
Method Details
-
main
Unit test: create a simple parser, parse and output the result.- Parameters:
asParam
- an array of parameters
-
parseXml
Parse the specified String into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments). In addition, the text value is trimmed for all nodes except leafs.- Parameters:
sXml
- the XML as string- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
parseXml
Parse the specified String into a tree of XmlElement objects (same as above) having the specified [empty] XmlElement a root. Note: this method is used by de-serialization (see SimpleElement#readExternal)- Parameters:
sXml
- the XML as stringelRoot
- the XML root- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
parseXml
Parse the specified InputStream into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments). In addition, the text value is trimmed for all nodes except leafs.- Parameters:
input
- the InputStream- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
parseXml
Parse the specified Reader into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments). In addition, the text value is trimmed for all nodes except leafs.- Parameters:
input
- the input Reader- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
parseXml
Parse the specified InputSource into a tree of XmlElement objects ignoring any XML nodes other than elements, text or comments (in a case of SaxParser that allows comments). In addition, the text value is trimmed for all nodes except leafs.- Parameters:
input
- the InputSource- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
parseXml
Actual implementation...- Parameters:
input
- the InputSourcexmlRoot
- the XML root- Returns:
- the generated XmlElement
- Throws:
SAXException
- if SAX error occurs
-
validateXsd
public void validateXsd(String sXml, XmlDocument xml) throws SAXException, IOException, ParserConfigurationException XSD aware parsing routine; if XML contains an XSD reference to a schemeLocation/noNamespaceSchemaLocation then parse XML using provided XSD for validation.- Parameters:
sXml
- the XML to parse (as a string)xml
- the XML document object used to obtain schema locations- Throws:
SAXException
- if XML contains an XSD reference and does not pass validationIOException
- if XML contains a schema that cannot be loadedParserConfigurationException
- if a parser cannot be created
-
resolveSchemaSources
For a given set of XSD URIs, return theSource
s to be used by the XML parser to validate an XML document.- Parameters:
listUri
- list of XSD URIs to convert- Returns:
- an array of
Source
s to be used by the XML parser - Throws:
IOException
- if the resource cannot be located or loaded
-
instantiateRoot
Instantiate an XmlElement implementation for a root element.- Parameters:
sRoot
- root name- Returns:
- a new XmlElement to be used as the root element
-
getParser
Get an instance of non-validating SAX parser.- Returns:
- a SAX parser
- Throws:
Exception
- if an error occurs
-