Skip to content

Instantly share code, notes, and snippets.

@jstutters
Created January 29, 2018 14:44
Show Gist options
  • Save jstutters/161185fa820a3a7fef6fabf255d48c50 to your computer and use it in GitHub Desktop.
Save jstutters/161185fa820a3a7fef6fabf255d48c50 to your computer and use it in GitHub Desktop.
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.FileInputStream;
public class Main {
public static void main(String[] args) {
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
try {
DocumentBuilder builder = factory.newDocumentBuilder();
FileInputStream fis = new FileInputStream("/tmp/header.xml");
InputSource is = new InputSource(fis);
Document doc = builder.parse(is);
Element element = doc.getDocumentElement();
NodeList nodes = element.getChildNodes();
for (int i = 0; i < nodes.getLength(); i++) {
System.out.println("" + nodes.item(i).getTextContent());
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment