Package ubic.gemma.core.util
Class XMLUtils
- java.lang.Object
-
- ubic.gemma.core.util.XMLUtils
-
public class XMLUtils extends Object
Handy methods for dealing with XML.- Author:
- pavlidis
-
-
Constructor Summary
Constructors Constructor Description XMLUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static XPathExpression
compile(String expr)
Compile an XPath expression.static DocumentBuilder
createDocumentBuilder()
Create a new DocumentBuilder with some good presets for Gemma.static NodeList
evaluate(XPathExpression xpath, Node item)
Evaluate an XPath expression that produces aNodeList
.static String
evaluateToString(XPathExpression xpath, Node item)
Evaluate an XPath expression that produces aNodeList
.static List<String>
extractMultipleChildren(Node parent, String elementName)
static Node
extractOneChild(Node parent, String elementName)
static String
extractOneChildText(Node parent, String elementName)
static Collection<String>
extractTagData(Document doc, String tag)
static Node
getItem(NodeList nodeList, int i)
Obtain an item from aNodeList
at a given index.static String
getTextValue(Node ele)
Make the horrible DOM API slightly more bearable: get the text value we know this element contains.static Node
getUniqueItem(NodeList nodeList)
Obtain a single item from aNodeList
.
-
-
-
Method Detail
-
createDocumentBuilder
public static DocumentBuilder createDocumentBuilder() throws ParserConfigurationException
Create a new DocumentBuilder with some good presets for Gemma.For security reasons (and also performance), the returned DocumentBuilder is not capable of resolving entities. If you need to resolve DTDs or XSD schemas, you must implement an
EntityResolver
.- Throws:
ParserConfigurationException
-
extractMultipleChildren
public static List<String> extractMultipleChildren(Node parent, String elementName)
-
extractTagData
public static Collection<String> extractTagData(Document doc, String tag)
- Parameters:
doc
- - the xml document to search throughtag
- -the name of the element we are looking for- Returns:
- a collection of strings that represent all the data contained within the given tag (for each instance of that tag)
-
getItem
public static Node getItem(NodeList nodeList, int i)
Obtain an item from aNodeList
at a given index.
-
getUniqueItem
public static Node getUniqueItem(NodeList nodeList)
Obtain a single item from aNodeList
.
-
getTextValue
public static String getTextValue(Node ele)
Make the horrible DOM API slightly more bearable: get the text value we know this element contains. Borrowed from the Spring API. Using Node.getTextContent() to fix failing tests, if there is a problem, see history before Feb 22. 2018 Also, this is the previous note (related to the code I removed): * Note that we can't really use the alternative Node.getTextContent() because it isn't supported by older Xerces * implementations (1.x), which tend to leak into the classloader. Causes recurring problems with tests.- Parameters:
ele
- element- Returns:
- text value
-
compile
public static XPathExpression compile(String expr)
Compile an XPath expression.
-
evaluate
public static NodeList evaluate(XPathExpression xpath, Node item)
Evaluate an XPath expression that produces aNodeList
.
-
evaluateToString
public static String evaluateToString(XPathExpression xpath, Node item)
Evaluate an XPath expression that produces aNodeList
.
-
-