Skip to content

Instantly share code, notes, and snippets.

@timothyshort
Created July 26, 2017 12:39
Show Gist options
  • Save timothyshort/1fcd48e0d5128527657d8f1bd734ab11 to your computer and use it in GitHub Desktop.
Save timothyshort/1fcd48e0d5128527657d8f1bd734ab11 to your computer and use it in GitHub Desktop.
This function reads an XML document to define global settings
// 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());
}
}
@nusratkhowaja
Copy link

please also incldue import files.

@timothyshort
Copy link
Author

I mention the import files on line 1
Dependencies: javax.xml.xpath | org.w3c | org.xml

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment