Created
July 26, 2017 12:39
-
-
Save timothyshort/1fcd48e0d5128527657d8f1bd734ab11 to your computer and use it in GitHub Desktop.
This function reads an XML document to define global settings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Dependencies: javax.xml.xpath | org.w3c | org.xml | |
public static void setFramework(String file) { | |
// 1. Prepare Xpath | |
XPathFactory xpf = XPathFactory.newInstance(); | |
XPath xPath = xpf.newXPath(); | |
try { | |
// 2. Create XML File | |
InputSource inputSource = new InputSource(file); | |
// 3. Use XPath location to find values | |
System.out.println(xPath.evaluate("/TestFramework/Location/Projects", inputSource, XPathConstants.STRING)); | |
System.out.println(((Element) (xPath.evaluate("/TestFramework/Browser", inputSource, XPathConstants.NODE))).getAttribute("Type")); | |
} catch (XPathExpressionException e) { | |
System.out.println("ERROR: Could not read XPath Expression"); | |
System.out.println(e.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I mention the import files on line 1
Dependencies: javax.xml.xpath | org.w3c | org.xml