本文整理汇总了Java中org.w3c.dom.traversal.TreeWalker.nextNode方法的典型用法代码示例。如果您正苦于以下问题:Java TreeWalker.nextNode方法的具体用法?Java TreeWalker.nextNode怎么用?Java TreeWalker.nextNode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.w3c.dom.traversal.TreeWalker
的用法示例。
在下文中一共展示了TreeWalker.nextNode方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getElementById
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public Element getElementById(String elementId)
{
Element element = xmljGetElementById(elementId);
if (element == null)
{
TreeWalker walker = createTreeWalker(this, NodeFilter.SHOW_ELEMENT,
null, false);
for (Node node = walker.nextNode(); node != null;
node = walker.nextNode())
{
GnomeElement e = (GnomeElement) node;
if (e.userIdAttrs != null)
{
for (Iterator i = e.userIdAttrs.iterator(); i.hasNext(); )
{
Attr attr = (Attr) i.next();
if (attr.getNodeValue().equals(elementId))
{
return e;
}
}
}
}
}
return element;
}
示例2: dropInitialAlef
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
private void dropInitialAlef(Document doc) throws DOMException {
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(MaryXML.TOKEN),
false);
Element m = null;
boolean prevEndsWithVowel = false;
while ((m = (Element) tw.nextNode()) != null) {
System.out.println("Element: "+m.getTagName());
if (m != null && m.getTagName().equals(MaryXML.TOKEN)) {
String transcription = m.getAttribute("ph");
System.out.println("transcription: "+transcription+", prevEndsWithVowel: "+prevEndsWithVowel);
if ( transcription.startsWith("' a ") && prevEndsWithVowel ) {
System.out.println("Removing A");
m.setAttribute("ph", transcription.replaceAll("^' a -?","' "));
}
if ( transcription.matches(".*[AUIaui][01]?$") ) {
prevEndsWithVowel = true;
}
}
}
}
示例3: vocaliseDoc
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
protected void vocaliseDoc(Document doc) throws Exception {
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t = null;
StringBuilder origText = new StringBuilder();
while ((t = (Element) tw.nextNode()) != null) {
//if (MaryDomUtils.hasAncestor(t, MaryXML.SAYAS) || t.hasAttribute("ph") || t.hasAttribute("sounds_like")) {
// ignore token
//continue;
origText.append(" " + MaryDomUtils.tokenText(t));
}
String vocText = vocaliseText(origText.toString());
String[] vocTextList = vocText.split(" ");
TreeWalker tw2 = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t2 = null;
int i = 0;
while ((t2 = (Element) tw2.nextNode()) != null && i < vocTextList.length) {
MaryDomUtils.setTokenText(t2, vocTextList[i]);
i++;
}
}
示例4: canProcessPunctuatedArabicToTokens
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
@Test
public void canProcessPunctuatedArabicToTokens() throws Exception {
// setup
MaryInterface mary = new LocalMaryInterface();
mary.setInputType(MaryDataType.TEXT.name());
mary.setOutputType(MaryDataType.TOKENS.name());
mary.setLocale(new Locale("ar"));
String example = "مدينة شِبام الأثريَّة التاريخيَّة، إحدى أقدم مُدن";
// exercise
Document doc = mary.generateXML(example);
// verify
assertNotNull(doc);
//We should get 8 tokens from this example, 7 words and one comma
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(MaryXML.TOKEN), false);
Element t = null;
int count = 0;
while ((t = (Element) tw.nextNode()) != null) {
count++;
}
assertEquals(8, count);
}
示例5: getLastElementByTagName
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
/**
* Get the last descendant element with the given tag name, or <code>null</code> if there is no such element.
*
* @param e
* e
* @param name
* name
* @return previous
*/
public static Element getLastElementByTagName(Element e, String name) {
// This implementation is certainly inefficient, but I have
// no better idea at the moment.
TreeWalker tw = ((DocumentTraversal) e.getOwnerDocument()).createTreeWalker(e, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(name), true);
Node current = null;
Node previous = null;
while ((current = tw.nextNode()) != null)
previous = current;
return (Element) previous;
}
示例6: isLastOfItsKindIn
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
public static boolean isLastOfItsKindIn(Node node, Node ancestor) {
if (node == null || ancestor == null)
return false;
Document doc = node.getOwnerDocument();
if (doc == null)
return false;
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(doc, NodeFilter.SHOW_ALL,
new NameNodeFilter(node.getNodeName()), true);
tw.setCurrentNode(node);
Node next = tw.nextNode();
return next == null || // no node with same name after this one
!isAncestor(ancestor, next); // next is not in the same ancestor
}
示例7: getNextOfItsKindIn
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
/**
* Find the Element with the same tag name as <code>element</code> following <code>element</code> within the same subtree
* under <code>root</code>. Precondition: <code>root</code> must be an ancestor of <code>element</code>.
*
* @param element
* element
* @param root
* root
* @return that Element, or <code>null</code> if there is no such Element.
*/
public static Element getNextOfItsKindIn(Element element, Element root) {
if (element == null || root == null)
return null;
String tagname = element.getTagName();
TreeWalker tw = ((DocumentTraversal) element.getOwnerDocument()).createTreeWalker(root, NodeFilter.SHOW_ELEMENT,
new NameNodeFilter(tagname), true);
tw.setCurrentNode(element);
for (Node next = tw.nextNode(); next != null; next = tw.nextNode()) {
if (next.getNodeName().equals(tagname)) {
return (Element) next;
}
}
return null;
}
示例8: ElementMap
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的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);
}
}
示例9: getFirstElementByTagName
import org.w3c.dom.traversal.TreeWalker; //导入方法依赖的package包/类
/**
* Get the first child element with the given tag name, or <code>null</code> if there is no such element.
*
* @param n
* n
* @param name
* name
* @return tx.nextNode
*/
public static Element getFirstElementByTagName(Node n, String name) {
Document doc = (n instanceof Document) ? (Document) n : n.getOwnerDocument();
TreeWalker tw = ((DocumentTraversal) doc).createTreeWalker(n, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(name), true);
return (Element) tw.nextNode();
}