Package gov.nasa.pds.tools.util
Class XMLExtractor
java.lang.Object
gov.nasa.pds.tools.util.XMLExtractor
public class XMLExtractor extends Object
Class to extract data from an XML file.
-
Field Summary
Fields Modifier and Type Field Description static StringDEFAULT_NAMESPACEstatic StringSCHEMA_LOCATION_XPATHstatic StringTARGET_NAMESPACEstatic StringXML_MODEL_XPATH -
Constructor Summary
Constructors Constructor Description XMLExtractor(File file)XMLExtractor(String url)Constructor.XMLExtractor(URL url)Constructor.XMLExtractor(Source xml)Constructor.XMLExtractor(InputSource source) -
Method Summary
Modifier and Type Method Description StringgetDefaultNamespace()SourcegetDocNode()Gets the document node of the XML document.net.sf.saxon.tree.tiny.TinyNodeImplgetNodeFromDoc(String expression)Gets a Node object from the given expression.net.sf.saxon.tree.tiny.TinyNodeImplgetNodeFromItem(String expression, Object item)Gets a Node object from the given expression.List<net.sf.saxon.tree.tiny.TinyNodeImpl>getNodesFromDoc(String expression)Gets Node objects from the given expression.List<net.sf.saxon.tree.tiny.TinyNodeImpl>getNodesFromItem(String expression, Object item)Gets Node objects from the given expression.StringgetSchemaLocation()StringgetSystemId()StringgetTargetNamespace()StringgetValueFromDoc(String expression)Gets the value of the given expression.StringgetValueFromItem(String expression, Object item)Gets the value of the given expression.List<String>getValuesFromDoc(String expression)Gets the values of the given expression.List<String>getValuesFromItem(String expression, Object item)Gets the values of the given expression.List<String>getXmlModels()
-
Field Details
-
SCHEMA_LOCATION_XPATH
- See Also:
- Constant Field Values
-
XML_MODEL_XPATH
- See Also:
- Constant Field Values
-
DEFAULT_NAMESPACE
- See Also:
- Constant Field Values
-
TARGET_NAMESPACE
- See Also:
- Constant Field Values
-
-
Constructor Details
-
XMLExtractor
Constructor.- Parameters:
xml- A parsed XML document.- Throws:
net.sf.saxon.trans.XPathException- If an error occurred while parsing the given xml file.XPathExpressionException- If an error occurred while setting up the default namespace.
-
XMLExtractor
Constructor.- Parameters:
xmlFile- An xml file.- Throws:
net.sf.saxon.trans.XPathException- If an error occurred while parsing the given xml file.XPathExpressionException- If an error occurred while setting up the default namespace.
-
XMLExtractor
public XMLExtractor(InputSource source) throws net.sf.saxon.trans.XPathException, XPathExpressionException- Throws:
net.sf.saxon.trans.XPathExceptionXPathExpressionException
-
XMLExtractor
public XMLExtractor(File file) throws net.sf.saxon.trans.XPathException, XPathExpressionException, MalformedURLException- Throws:
net.sf.saxon.trans.XPathExceptionXPathExpressionExceptionMalformedURLException
-
XMLExtractor
public XMLExtractor(String url) throws net.sf.saxon.trans.XPathException, XPathExpressionException, MalformedURLExceptionConstructor.- Parameters:
xmlFile- An xml file.- Throws:
net.sf.saxon.trans.XPathException- If an error occurred while parsing the given xml file.XPathExpressionException- If an error occurred while setting up the default namespace.MalformedURLException
-
-
Method Details
-
getValueFromDoc
public String getValueFromDoc(String expression) throws XPathExpressionException, net.sf.saxon.trans.XPathExceptionGets the value of the given expression.- Parameters:
expression- An XPath expression.- Returns:
- The resulting value or null if nothing was found.
- Throws:
XPathExpressionException- If the given expression was malformed.net.sf.saxon.trans.XPathException
-
getValueFromItem
Gets the value of the given expression.- Parameters:
expression- An XPath expression.item- The starting point from which to evaluate the XPath expression.- Returns:
- The resulting value or null if nothing was found.
- Throws:
XPathExpressionException- If the given expression was malformed.
-
getNodeFromDoc
public net.sf.saxon.tree.tiny.TinyNodeImpl getNodeFromDoc(String expression) throws XPathExpressionException, net.sf.saxon.trans.XPathExceptionGets a Node object from the given expression.- Parameters:
expression- An XPath expression.- Returns:
- A Node object.
- Throws:
XPathExpressionException- If the given expression was malformed.net.sf.saxon.trans.XPathException
-
getNodeFromItem
public net.sf.saxon.tree.tiny.TinyNodeImpl getNodeFromItem(String expression, Object item) throws XPathExpressionExceptionGets a Node object from the given expression.- Parameters:
expression- An XPath expression.item- The starting point from which to evaluate the XPath expression.- Returns:
- A Node object.
- Throws:
XPathExpressionException- If the given expression was malformed.
-
getValuesFromDoc
public List<String> getValuesFromDoc(String expression) throws XPathExpressionException, net.sf.saxon.trans.XPathExceptionGets the values of the given expression.- Parameters:
expression- An XPath expression.- Returns:
- The resulting values or an empty list if nothing was found.
- Throws:
XPathExpressionException- If the given expression was malformed.net.sf.saxon.trans.XPathException
-
getValuesFromItem
public List<String> getValuesFromItem(String expression, Object item) throws XPathExpressionExceptionGets the values of the given expression.- Parameters:
expression- An XPath expression.item- The starting point from which to evaluate the XPath expression.- Returns:
- The resulting values or an empty list if nothing was found.
- Throws:
XPathExpressionException- If the given expression was malformed.
-
getDocNode
Gets the document node of the XML document.- Returns:
- The Document Node.
- Throws:
net.sf.saxon.trans.XPathException
-
getNodesFromDoc
public List<net.sf.saxon.tree.tiny.TinyNodeImpl> getNodesFromDoc(String expression) throws XPathExpressionException, net.sf.saxon.trans.XPathExceptionGets Node objects from the given expression.- Parameters:
expression- An XPath expression.- Returns:
- A NodeList object.
- Throws:
XPathExpressionException- If the given expression was malformed.net.sf.saxon.trans.XPathException
-
getNodesFromItem
public List<net.sf.saxon.tree.tiny.TinyNodeImpl> getNodesFromItem(String expression, Object item) throws XPathExpressionExceptionGets Node objects from the given expression.- Parameters:
expression- An XPath expression.item- The starting point from which to evaluate the XPath expression.- Returns:
- A NodeList object.
- Throws:
XPathExpressionException- If the given expression was malformed.
-
getSchemaLocation
public String getSchemaLocation() throws XPathExpressionException, net.sf.saxon.trans.XPathException- Returns:
- Returns the schemalocation attribute value from the label. If it was not found, a null value will be returned.
- Throws:
XPathExpressionExceptionnet.sf.saxon.trans.XPathException
-
getXmlModels
public List<String> getXmlModels() throws XPathExpressionException, net.sf.saxon.trans.XPathException- Returns:
- Returns the schematron specifications in the label.
- Throws:
XPathExpressionExceptionnet.sf.saxon.trans.XPathException
-
getDefaultNamespace
public String getDefaultNamespace() throws XPathExpressionException, net.sf.saxon.trans.XPathException- Returns:
- Returns the 'xmlns' attribute of the document (default namespace)
- Throws:
XPathExpressionExceptionnet.sf.saxon.trans.XPathException
-
getTargetNamespace
public String getTargetNamespace() throws XPathExpressionException, net.sf.saxon.trans.XPathException- Returns:
- Returns the 'targetNamespace' attribute of the document (default namespace)
- Throws:
XPathExpressionExceptionnet.sf.saxon.trans.XPathException
-
getSystemId
-