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
All Methods Instance Methods Concrete Methods 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 Detail
-
SCHEMA_LOCATION_XPATH
public static final String SCHEMA_LOCATION_XPATH
- See Also:
- Constant Field Values
-
XML_MODEL_XPATH
public static final String XML_MODEL_XPATH
- See Also:
- Constant Field Values
-
DEFAULT_NAMESPACE
public static final String DEFAULT_NAMESPACE
- See Also:
- Constant Field Values
-
TARGET_NAMESPACE
public static final String TARGET_NAMESPACE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
XMLExtractor
public XMLExtractor(Source xml) throws XPathExpressionException, net.sf.saxon.trans.XPathException
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
public XMLExtractor(URL url) throws net.sf.saxon.trans.XPathException, XPathExpressionException
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, MalformedURLException
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.MalformedURLException
-
-
Method Detail
-
getValueFromDoc
public String getValueFromDoc(String expression) throws XPathExpressionException, net.sf.saxon.trans.XPathException
Gets 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
public String getValueFromItem(String expression, Object item) throws XPathExpressionException
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.XPathException
Gets 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 XPathExpressionException
Gets 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.XPathException
Gets 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 XPathExpressionException
Gets 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
public Source getDocNode() throws net.sf.saxon.trans.XPathException
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.XPathException
Gets 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 XPathExpressionException
Gets 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
public String getSystemId()
-
-