Code, JavaEE

JDomUtil


public class JDomUtil {

public File loadXMLFile(String fullFilePath) {
 File fileToReturn = new File(fullFilePath);
 return fileToReturn;
 }

public Document createInMemoryXMLDocument(File xmlFile) {
 Document document = null;
 try {
 document = new SAXBuilder().build(xmlFile);
 } catch (JDOMException e) {
 System.out.printf("%n%s", e.toString());
 } catch (IOException e) {
 System.out.printf("%n%s", e.toString());
 }
 return document;
 }

public List<Element> navigateToDesiredXMLContent(String xpathExpr, Document document) {
 XPath xPath = null;
 List<Element> contentList = null;
 try {
 xPath = XPath.newInstance(xpathExpr);
 contentList = xPath.selectNodes(document);
 } catch (JDOMException e) {
 System.out.printf("%n%s", e.toString());
 }
 return contentList;
 }
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s