本文整理汇总了Java中org.w3c.dom.traversal.DocumentTraversal.createTreeWalker方法的典型用法代码示例。如果您正苦于以下问题:Java DocumentTraversal.createTreeWalker方法的具体用法?Java DocumentTraversal.createTreeWalker怎么用?Java DocumentTraversal.createTreeWalker使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.traversal.DocumentTraversal
的用法示例。
在下文中一共展示了DocumentTraversal.createTreeWalker方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
@BeforeClass
public static void init() throws IOException, CSSException, SAXException {
log.info("\n\n\n == AnalyzerTest test at {} == \n\n\n", new Date());
DOMSource ds = new DOMSource(AnalyzerTest.class.getResourceAsStream("/simple/data.html"));
doc = ds.parse();
sheet = CSSFactory.parse(AnalyzerTest.class.getResource("/simple/data.css"), null);
analyzer = new Analyzer(sheet);
NodeList list = doc.getElementsByTagName("body");
assertEquals("There is one <body> element", 1, list.getLength());
//walker = new TidyTreeWalker(list.item(0), NodeFilter.SHOW_ELEMENT);
DocumentTraversal traversal = (DocumentTraversal) doc;
walker = traversal.createTreeWalker(list.item(0), NodeFilter.SHOW_ELEMENT, null, false);
elements = new ElementMap(doc);
}
示例2: parseDocument
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
private void parseDocument(Document dasDoc, String chr, List<Feature> features) {
try {
DocumentTraversal traversal = (DocumentTraversal) dasDoc;
TreeWalker treewalker = traversal.createTreeWalker(
dasDoc.getDocumentElement(), NodeFilter.SHOW_ELEMENT, null, true);
parseTree(treewalker, "FEATURE", chr, features);
} catch (Exception ex) {
log.error(ex);
throw new DataLoadException("Error loading DAS resource (" + ex.toString() + ")", getPath());
}
}
示例3: Traversal
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
public Traversal(Document doc, Object source, int whatToShow) {
if (doc instanceof DocumentTraversal) {
DocumentTraversal dt = (DocumentTraversal) doc;
this.walker = dt.createTreeWalker(doc.getDocumentElement(), whatToShow, null, false);
} else {
this.walker = new GenericTreeWalker(doc.getDocumentElement(), whatToShow);
}
this.source = source;
}
示例4: augmentDocument
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
/**
* Iterates through all the ELEMENT nodes in a document and gives them ids
* if they don't already have them.
*
* @param document
*/
public static void augmentDocument(Document document) {
final DocumentTraversal traversal = (DocumentTraversal) document;
final TreeWalker walker = traversal.createTreeWalker(document, NodeFilter.SHOW_ELEMENT, null, true);
traverseLevel(walker, 0);
}
示例5: ElementMap
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
public ElementMap(Document doc) {
elementIDs = new HashMap<String, Element>();
elementNames = new HashMap<String, Element>();
DocumentTraversal traversal = (DocumentTraversal) doc;
TreeWalker w = traversal.createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, null, false);
//TreeWalker w = new TidyTreeWalker(doc, NodeFilter.SHOW_ELEMENT);
Element current;
while ((current = (Element) w.nextNode()) != null) {
elementNames.put(current.getNodeName().toLowerCase(), current);
String id = current.getAttribute("id");
if(id!=null)
elementIDs.put(id, current);
}
}
示例6: DOMTreeWalkerTreeModel
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
/**
* Create a TreeModel for a TreeWalker that returns all nodes in the
* specified document
**/
public DOMTreeWalkerTreeModel(Document document) {
DocumentTraversal dt = (DocumentTraversal) document;
walker = dt
.createTreeWalker(document, NodeFilter.SHOW_ALL, null, false);
}
示例7: main
import org.w3c.dom.traversal.DocumentTraversal; //导入方法依赖的package包/类
/**
* This main() method demonstrates the use of this class, the use of the
* Xerces DOM parser, and the creation of a DOM Level 2 TreeWalker object.
**/
public static void main(String[] args) throws IOException, SAXException {
// Obtain an instance of a Xerces parser to build a DOM tree.
// Note that we are not using the JAXP API here, so this
// code uses Apache Xerces APIs that are not standards
DOMParser parser = new org.apache.xerces.parsers.DOMParser();
// Get a java.io.Reader for the input XML file and
// wrap the input file in a SAX input source
Reader in = new BufferedReader(new FileReader(args[0]));
InputSource input = new org.xml.sax.InputSource(in);
// Tell the Xerces parser to parse the input source
parser.parse(input);
// Ask the parser to give us our DOM Document. Once we've got the DOM
// tree, we don't have to use the Apache Xerces APIs any more; from
// here on, we use the standard DOM APIs
Document document = parser.getDocument();
// If we're using a DOM Level 2 implementation, then our Document
// object ought to implement DocumentTraversal
DocumentTraversal traversal = (DocumentTraversal) document;
// For this demonstration, we create a NodeFilter that filters out
// Text nodes containing only space; these just clutter up the tree
NodeFilter filter = new NodeFilter() {
public short acceptNode(Node n) {
if (n.getNodeType() == Node.TEXT_NODE) {
// Use trim() to strip off leading and trailing space.
// If nothing is left, then reject the node
if (((Text) n).getData().trim().length() == 0)
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
};
// This set of flags says to "show" all node types except comments
int whatToShow = NodeFilter.SHOW_ALL & ~NodeFilter.SHOW_COMMENT;
// Create a TreeWalker using the filter and the flags
TreeWalker walker = traversal.createTreeWalker(document, whatToShow,
filter, false);
// Instantiate a TreeModel and a JTree to display it
JTree tree = new JTree(new DOMTreeWalkerTreeModel(walker));
// Create a frame and a scrollpane to display the tree, and pop them up
JFrame frame = new JFrame("DOMTreeWalkerTreeModel Demo");
frame.getContentPane().add(new JScrollPane(tree));
frame.setSize(500, 250);
frame.setVisible(true);
}