Skip to content

Instantly share code, notes, and snippets.

@joesavak
Created December 6, 2010 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joesavak/730985 to your computer and use it in GitHub Desktop.
Save joesavak/730985 to your computer and use it in GitHub Desktop.
Reader in = new BufferedReader(new FileReader(fileName));
Input Source input = new InputSource(in);
DOMParser parser = new DOMParser();
int whatToShow = NodeFilter.SHOW_ALL;
NodeFilter filter = new NodeFilter() {
public short acceptNode(Node n) {
if (n.getNodeType() == Node.TEXT_NODE) {
if(((Text)n).getData().trim().length() == 0)
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
};
parser.parse(input);
in.close();
Document doc = parser.getDocument();
DocumentTraversal traversal = (DocumentTraversal)doc;
TreeWalker walker = traversal.createTreeWalker(doc, whatToShow, filter, false);
//now we have a tree we can recursively walk down to create the needed staging tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment