当前位置: 首页>>代码示例>>Java>>正文


Java DocumentTraversal类代码示例

本文整理汇总了Java中org.w3c.dom.traversal.DocumentTraversal的典型用法代码示例。如果您正苦于以下问题:Java DocumentTraversal类的具体用法?Java DocumentTraversal怎么用?Java DocumentTraversal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DocumentTraversal类属于org.w3c.dom.traversal包,在下文中一共展示了DocumentTraversal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dropInitialAlef

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的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;
	}
	
    }
}
   }
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:22,代码来源:Postlex.java

示例2: filterPunctuation

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
protected void filterPunctuation(MaryData d) {
    Document doc = d.getDocument();
    NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(doc, NodeFilter.SHOW_ELEMENT, new NameNodeFilter(
														    MaryXML.PARAGRAPH), false);
    Element p = null;
    while ((p = (Element) ni.nextNode()) != null) {
	Node textNode = p.getFirstChild();
	String s = textNode.getNodeValue();

	System.err.println("FilterPunctuation");
	System.err.println(s);

	s = s.replaceAll("،", ",");
	//s = s.replaceAll("XX", "YY");

	System.err.println(s);

	textNode.setNodeValue(s);
    }
}
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:21,代码来源:JTokeniser.java

示例3: vocaliseDoc

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的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++;
}
   }
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:27,代码来源:Preprocess.java

示例4: getPlainTextBelow

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
 * Return the concatenation of the values of all text nodes below the given node. One space character is inserted between
 * adjacent text nodes.
 * 
 * @param n
 *            n
 * @return null if n is null
 */
public static String getPlainTextBelow(Node n) {
	if (n == null)
		return null;
	Document doc = null;
	if (n.getNodeType() == Node.DOCUMENT_NODE) {
		doc = (Document) n;
	} else {
		doc = n.getOwnerDocument();
	}
	StringBuilder buf = new StringBuilder();
	NodeIterator it = ((DocumentTraversal) doc).createNodeIterator(n, NodeFilter.SHOW_TEXT, null, true);
	Text text = null;
	while ((text = (Text) it.nextNode()) != null) {
		buf.append(text.getData().trim());
		buf.append(" ");
	}
	return buf.toString();
}
 
开发者ID:MyRobotLab,项目名称:myrobotlab,代码行数:27,代码来源:DomUtils.java

示例5: 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);
}
 
开发者ID:radkovo,项目名称:jStyleParser,代码行数:20,代码来源:AnalyzerTest.java

示例6: outputDebug

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
 * Outputs information on the matches for debug purposes.
 * 
 * @param matchSet The set of matching Nodes.
 * @param doc The first document being differenced
 */
private static void outputDebug(final NodePairs matchSet,
        final Document doc) {
    
    if (DiffFactory.isDebug()) {
        NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
                doc.getDocumentElement(), NodeFilter.SHOW_ALL, null, false);
 
        Node n;
        while ((n = ni.nextNode()) != null) {
            System.err.print(DOMOps.getNodeAsString(n));
            if (matchSet.isMatched(n)) {
                System.err.println(" matches "
                        + DOMOps.getNodeAsString(matchSet.getPartner(n)));
            } else {
                System.err.println(" unmatched");
            }
        }
        
        ni.detach();
        System.err.println();
    }
}
 
开发者ID:amouat,项目名称:diffxml,代码行数:29,代码来源:Match.java

示例7: initialiseAndOrderNodes

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
 * Returns a list of Nodes sorted according to their depths.
 * 
 * Does *NOT* include root or documentElement
 * 
 * TreeSet is sorted in reverse order of depth according to
 * NodeInfoComparator.
 * 
 * @param doc The document to be initialised and ordered.
 * @return A depth-ordered list of the nodes in the doc.
 */
private static List<NodeDepth> initialiseAndOrderNodes(
        final Document doc) {

    NodeIterator ni = ((DocumentTraversal) doc).createNodeIterator(
            doc, NodeFilter.SHOW_ALL, null, false);

    List<NodeDepth> depthSorted = new ArrayList<NodeDepth>();
         
    Node n;
    while ((n = ni.nextNode()) != null) {
        if (!(NodeOps.checkIfSameNode(doc, n) 
                || NodeOps.checkIfSameNode(doc.getDocumentElement(), n)
                || n.getNodeType() == Node.DOCUMENT_TYPE_NODE)) {
            depthSorted.add(new NodeDepth(n));
        }
    }
    
    ni.detach();
    Collections.sort(depthSorted, new NodeDepthComparator());
    
    return depthSorted;
}
 
开发者ID:amouat,项目名称:diffxml,代码行数:34,代码来源:Match.java

示例8: getElementsByTagNameCaseInsensitive

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
public static List<Element> getElementsByTagNameCaseInsensitive(Document doc,
    final Set<String> lowerCaseNames) {
  final List<Element> result = Lists.newArrayList();
  NodeIterator nodeIterator = ((DocumentTraversal) doc)
      .createNodeIterator(doc, NodeFilter.SHOW_ELEMENT,
          new NodeFilter() {
            public short acceptNode(Node n) {
              if (lowerCaseNames.contains(n.getNodeName().toLowerCase())) {
                return NodeFilter.FILTER_ACCEPT;
              }
              return NodeFilter.FILTER_REJECT;
            }
          }, false);
  for (Node n = nodeIterator.nextNode(); n != null ; n = nodeIterator.nextNode()) {
    result.add((Element)n);
  }
  return result;
}
 
开发者ID:inevo,项目名称:shindig-1.1-BETA5-incubating,代码行数:19,代码来源:DomUtil.java

示例9: checkDocument

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
private boolean checkDocument() {
	while (true) {
		if (this.document != panel.getDocument() || textInlineMap == null) {
			this.document = panel.getDocument();
			textInlineMap = null;
			this.dotInfo = null;
			this.markInfo = null;
			this.lastSelectionRange = null;
			try {
				this.docRange = (DocumentRange) panel.getDocument();
				this.docTraversal = (DocumentTraversal) panel.getDocument();
				if (this.document != null && this.createMaps()) {
					return true;
				}
				try {
					Thread.sleep(10);
				} catch (InterruptedException e) {
					return false;
				}
			} catch (ClassCastException cce) {
				XRLog.layout(Level.WARNING, "Document instance cannot create ranges: no selection possible");
				return false;
			}
		}
		return true;
	}
}
 
开发者ID:rockfireredmoon,项目名称:icetone,代码行数:28,代码来源:XHTMLSelectionHighlighter.java

示例10: getDocumentTraversal

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
DocumentTraversal getDocumentTraversal(Document doc)
  throws XMLStreamException
{
  DOMImplementation dom = doc.getImplementation();
  if (!dom.hasFeature("Traversal", "2.0"))
    throw new XMLStreamException("Traversal not supported");
  return (DocumentTraversal) doc;
}
 
开发者ID:vilie,项目名称:javify,代码行数:9,代码来源:XIncludeFilter.java

示例11: 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());
            }
        }
 
开发者ID:hyounesy,项目名称:ALEA,代码行数:14,代码来源:DASFeatureSource.java

示例12: XmiDomTree

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的package包/类
/**
 *
 * @param filePath
 * @param defaultPackageName
 * @throws Exception
 */
public XmiDomTree(String filePath, String defaultPackageName) throws Exception {
    Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(filePath);
    xmiTree = ((DocumentTraversal) document).createTreeWalker(document.getDocumentElement(), NodeFilter.SHOW_ALL, new XmiNodeFilter(), true);
    initializeCollections(defaultPackageName);
    checkXmiVersion(document);
}
 
开发者ID:proyecto-adalid,项目名称:adalid,代码行数:13,代码来源:XmiDomTree.java

示例13: 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;
}
 
开发者ID:mantlik,项目名称:swingbox-javahelp-viewer,代码行数:10,代码来源:Traversal.java

示例14: canProcessPunctuatedArabicToTokens

import org.w3c.dom.traversal.DocumentTraversal; //导入依赖的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);


   }
 
开发者ID:HaraldBerthelsen,项目名称:marytts-lang-ar,代码行数:29,代码来源:MaryInterfaceArIT.java

示例15: 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);
}
 
开发者ID:openimaj,项目名称:openimaj,代码行数:14,代码来源:Readability.java


注:本文中的org.w3c.dom.traversal.DocumentTraversal类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。