Java 类org.w3c.dom.traversal.TreeWalker 实例源码

项目:convertigo-engine    文件:Sequence.java   
private static void traverseLevel(TreeWalker walker, Element topParent, String indent) {
    // describe current node:
    Element current = (Element) walker.getCurrentNode();
    //System.out.println(indent + "- " + ((Element) current).getTagName());

    // store elements which need to be moved
    if (topParent != null) {
        Element parent = (Element) current.getParentNode();
        if (parent != null && !topParent.equals(parent)) {
            OutputFilter outputFilter = (OutputFilter)walker.getFilter();
            outputFilter.getToAddList(topParent).add(current);
        }
    }

    // traverse children:
    for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
      traverseLevel(walker, current, indent + '\t');
    }

    // return position to the current (level up):
    walker.setCurrentNode(current);
}
项目:jnieasy    文件:TypeNativeDirectCallbackXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >
    TypeNativeDirectCallbackImpl typeDec = getTypeNativeDirectCallback();

    // En el caso de user defined puede estar ya definida la signatura
    // por lo que la carga de una nueva es opcional y se hace si detectamos que
    // que en el XML se actualiza la signatura      

    if ((typeDec.getBehaviorSignature() == null) || TreeWalkerUtil.hasChildElement(walker))
    {
        // Una vez aqu� dentro, deben existir nodos de declaraci�n de la signatura o falla
        NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
        sigXML.parse(typeNode,walker,ctx);
        typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
    }
}
项目:javify    文件:GnomeDocument.java   
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;
}
项目:ALEA    文件:DASFeatureSource.java   
private List<Feature> parseTree(TreeWalker walker,
                                String tag,
                                String chr,
                                List<Feature> features) {

    Node parent = walker.getCurrentNode();
    Element n = (Element) walker.firstChild();
    while (n != null) {
        if (n.getTagName().equalsIgnoreCase(tag)) {
            Feature f = getFeature(walker, chr);
            if (f != null) {
                features.add(f);
            }

            n = (Element) walker.nextSibling();
            continue;
        }
        parseTree(walker, tag, chr, features);
        n = (Element) walker.nextSibling();
    }
    walker.setCurrentNode(parent);
    return features;
}
项目:jvm-stm    文件:GnomeDocument.java   
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;
}
项目:adalid    文件:XmiDomTree.java   
private void setPackageToElements(TreeWalker tw, String currentPackage) {
    Node n = tw.getCurrentNode();
    XmiElement element = new XmiElement((Element) n, this);
    if (isPackageElement(element)) {
        if (currentPackage.isEmpty()) {
            currentPackage = element.getNameTag();
        } else {
            currentPackage = currentPackage + XmiTags.SEPARATOR + element.getNameTag();
        }
        logger.debug("Current package has changed " + currentPackage);
    } else if (elementIdMap.get(element.getXmiId()) != null) {
        elementIdMap.get(element.getXmiId()).setPackageContainer(currentPackage);
    }
    for (Node child = tw.firstChild();
        child != null;
        child = tw.nextSibling()) {
        setPackageToElements(tw, currentPackage);
    }
    tw.setCurrentNode(n);
}
项目:marytts-lang-ar    文件:Postlex.java   
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;
    }

    }
}
   }
项目:marytts-lang-ar    文件:Preprocess.java   
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++;
}
   }
项目:openimaj    文件:Readability.java   
private static int traverseLevel(TreeWalker walker, int counter) {
    // describe current node:
    final Node parend = walker.getCurrentNode();

    if (parend instanceof Element) {
        if (((Element) parend).getAttribute("id").length() == 0) {
            ((Element) parend).setAttribute("id", "gen-id-" + counter);
            counter++;
        }
    }

    // traverse children:
    for (Node n = walker.firstChild(); n != null; n = walker.nextSibling()) {
        counter = traverseLevel(walker, counter);
    }

    // return position to the current (level up):
    walker.setCurrentNode(parend);

    return counter;
}
项目:JamVM-PH    文件:GnomeDocument.java   
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;
}
项目:classpath    文件:GnomeDocument.java   
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;
}
项目:convertigo-engine    文件:Sequence.java   
private static void buildOutputDom(Element root, OutputFilter outputFilter) {
    try {
        TreeWalker walker = new TwsTreeWalker(root, NodeFilter.SHOW_ELEMENT, outputFilter, false);
        traverseLevel(walker,null,"");
        outputFilter.doOutPut();
    }
    finally {
        if (outputFilter != null) {
            outputFilter.map.clear();
        }
    }
}
项目:OpenJSharp    文件:DocumentImpl.java   
/**
 * Create and return a TreeWalker.
 *
 * @param root The root of the iterator.
 * @param whatToShow The whatToShow mask.
 * @param filter The NodeFilter installed. Null means no filter.
 * @param entityReferenceExpansion true to expand the contents of
 *                                 EntityReference nodes
 * @since WD-DOM-Level-2-19990923
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
{
    if (root == null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
    }
    return new TreeWalkerImpl(root, whatToShow, filter,
                              entityReferenceExpansion);
}
项目:openjdk-jdk10    文件:DocumentImpl.java   
/**
 * Create and return a TreeWalker.
 *
 * @param root The root of the iterator.
 * @param whatToShow The whatToShow mask.
 * @param filter The NodeFilter installed. Null means no filter.
 * @param entityReferenceExpansion true to expand the contents of
 *                                 EntityReference nodes
 * @since WD-DOM-Level-2-19990923
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
{
    if (root == null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
    }
    return new TreeWalkerImpl(root, whatToShow, filter,
                              entityReferenceExpansion);
}
项目:openjdk9    文件:DocumentImpl.java   
/**
 * Create and return a TreeWalker.
 *
 * @param root The root of the iterator.
 * @param whatToShow The whatToShow mask.
 * @param filter The NodeFilter installed. Null means no filter.
 * @param entityReferenceExpansion true to expand the contents of
 *                                 EntityReference nodes
 * @since WD-DOM-Level-2-19990923
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
{
    if (root == null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
    }
    return new TreeWalkerImpl(root, whatToShow, filter,
                              entityReferenceExpansion);
}
项目:jnieasy    文件:JavaClassAsNativeObjectFieldContainerEnhancerXML.java   
public static CtField getCtFieldFromXMLDirectly(Element classNode,CtClass ctClass)
{
    TreeWalker walker = TreeWalkerUtil.createTreeWalker(classNode);
    Element fieldNode = TreeWalkerUtil.firstChildElement(walker, FieldOfClassXML.fieldTagName(), true);
    String fieldName = FieldOfClassXML.getName(fieldNode);  
    try
    {
        return ctClass.getDeclaredField(fieldName);
    }
    catch(NotFoundException ex)
    {
        throw new JNIEasyException(ex);
    }
}
项目:jnieasy    文件:TreeWalkerUtil.java   
public static TreeWalker createTreeWalker(Element node)
{
    //DocumentTraversal doc = (DocumentTraversal)node.getOwnerDocument();
    //return doc.createTreeWalker(node,NodeFilter.SHOW_ELEMENT,null,true);        

    return new TreeWalkerImpl(node,NodeFilter.SHOW_ELEMENT,null,true);
}
项目:jnieasy    文件:TreeWalkerUtil.java   
public static boolean hasChildElement(TreeWalker walker)
{
    Node current = walker.getCurrentNode();
    Node child = walker.firstChild();
    if (child != null)
    {
        walker.setCurrentNode(current);
        return true;
    }
    return false;
}
项目:jnieasy    文件:TreeWalkerUtil.java   
private static void checkElement(Element childNode,TreeWalker walker,String tagName,boolean mustExist,String type)
{
    if (childNode == null)
    {
        if (mustExist)
            throw new JNIEasyXMLException("Expected a " + type + " element (<" + tagName + ">)",walker.getCurrentNode());
    }
    else if ((tagName != null) && !childNode.getTagName().equals(tagName))
            throw new JNIEasyXMLException("Expected element with tag name: \"" + tagName + "\"",childNode);
}
项目:jnieasy    文件:TreeWalkerUtil.java   
private static void checkElement(Element childNode,TreeWalker walker,boolean mustExist,String type)
{
    if (childNode == null)
    {
        if (mustExist)
            throw new JNIEasyXMLException("Expected a " + type + " element",walker.getCurrentNode());
    }
}
项目:jnieasy    文件:JavaClassAsNativeMultipleFieldContainerXML.java   
public void parse(Element classNode,TreeWalker walker)
{
    // Ej. <class name="SimpleClassName" libraryPath="User32.dll">

    JavaClassAsNativeMultipleFieldContainerImpl javaClass = getJavaClassAsMultipleFieldContainer();

    Attr libPathAtt = classNode.getAttributeNode("libraryPath");
    if (libPathAtt != null)
    {
        String libraryPath = libPathAtt.getValue();        
        javaClass.setLibraryPath(libraryPath);        
    }
}
项目:jnieasy    文件:ConstructorOfClassXML.java   
public void parse(Element constrNode,TreeWalker walker,TaskContext ctx)
{
    ClassTypeNativeMultipleFieldContainerImpl thisClassType = (ClassTypeNativeMultipleFieldContainerImpl)getJavaClassAsNativeCapable().getClassTypeNativeCapable();

    ConstructorSignatureXML sigXML = ConstructorSignatureXML.newConstructorSignatureXML();
    sigXML.setThisClassType(thisClassType);
    sigXML.parse(constrNode,walker,ctx);
    NativeConstructorSignatureImpl sig = sigXML.getConstructorSignature();

    ConstructorOfClassImpl constr = ConstructorOfClassImpl.newConstructorOfClass(sig,thisClassType);
    setConstructorOfClass(constr);
}
项目:jnieasy    文件:TypeDLLBehaviorXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >

    TypeDLLBehaviorImpl typeDec = getTypeDLLBehavior();
    NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
    sigXML.parse(typeNode,walker,ctx);
    typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
项目:jnieasy    文件:TypeNativeBehaviorDefaultXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >
    TypeNativeBehaviorDefaultImpl typeDec = getTypeNativeBehaviorDefault();
    NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
    sigXML.parse(typeNode,walker,ctx);
    typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
项目:jnieasy    文件:TypeNativeBehaviorReflectionWrapperXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >
    TypeNativeBehaviorReflectionWrapperImpl typeDec = getTypeNativeBehaviorReflectionWrapper();
    NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
    sigXML.parse(typeNode,walker,ctx);
    typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
项目:jnieasy    文件:TypeNativeCallbackDefaultXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >
    TypeNativeCallbackDefaultImpl typeDec = getTypeNativeCallbackDefault();
    NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
    sigXML.parse(typeNode,walker,ctx);
    typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
项目:jnieasy    文件:TypeNativeBehaviorReflectionXML.java   
public void parse(Element typeNode,TreeWalker walker,TaskContext ctx)
{
    super.parse(typeNode,walker,ctx);

    // <field/component ... >

    TypeNativeBehaviorReflectionImpl typeDec = getTypeNativeBehaviorReflection();
    NativeBehaviorSignatureXML sigXML = typeDec.newBehaviorSignatureXML();
    sigXML.parse(typeNode,walker,ctx);
    typeDec.setBehaviorSignature(sigXML.getBehaviorSignature());
}
项目:jnieasy    文件:TypeNativePrimitiveXML.java   
public void parse(Element typeNode, TreeWalker walker, TaskContext ctx)
{
    super.parse(typeNode, walker, ctx);

    TypeNativePrimitiveImpl typeDec = getTypeNativePrimitive();
    parseAttMemSize(typeNode,typeDec);
}
项目:Push2Display    文件:AbstractDocument.java   
/**
 * <b>DOM</b>: Implements {@link
 * DocumentTraversal#createTreeWalker(Node,int,NodeFilter,boolean)}.
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
    throws DOMException {
    return TraversalSupport.createTreeWalker(this, root, whatToShow,
                                             filter,
                                             entityReferenceExpansion);
}
项目:Push2Display    文件:TraversalSupport.java   
/**
 * Creates a new tree walker.
 */
public static TreeWalker createTreeWalker(AbstractDocument doc,
                                          Node root,
                                          int whatToShow, 
                                          NodeFilter filter, 
                                          boolean entityReferenceExpansion) {
    if (root == null) {
        throw doc.createDOMException
            (DOMException.NOT_SUPPORTED_ERR, "null.root",  null);
    }
    return new DOMTreeWalker(root, whatToShow, filter,
                             entityReferenceExpansion);
}
项目:lookaside_java-1.8.0-openjdk    文件:DocumentImpl.java   
/**
 * Create and return a TreeWalker.
 *
 * @param root The root of the iterator.
 * @param whatToShow The whatToShow mask.
 * @param filter The NodeFilter installed. Null means no filter.
 * @param entityReferenceExpansion true to expand the contents of
 *                                 EntityReference nodes
 * @since WD-DOM-Level-2-19990923
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
{
    if (root == null) {
        String msg = DOMMessageFormatter.formatMessage(DOMMessageFormatter.DOM_DOMAIN, "NOT_SUPPORTED_ERR", null);
        throw new DOMException(DOMException.NOT_SUPPORTED_ERR, msg);
    }
    return new TreeWalkerImpl(root, whatToShow, filter,
                              entityReferenceExpansion);
}
项目:javify    文件:GnomeDocument.java   
public TreeWalker createTreeWalker(Node root,
                                  int whatToShow,
                                  NodeFilter filter,
                                  boolean entityReferenceExpansion)
  throws DOMException
{
  return new DomNodeIterator(root, whatToShow, filter,
                             entityReferenceExpansion, true);
}
项目:javify    文件:DomDocument.java   
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean expandEntities)
{
  return new DomNodeIterator(root, whatToShow, filter, expandEntities,
                             true);
}
项目:ALEA    文件:DASFeatureSource.java   
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());
            }
        }
项目:jvm-stm    文件:GnomeDocument.java   
public TreeWalker createTreeWalker(Node root,
                                  int whatToShow,
                                  NodeFilter filter,
                                  boolean entityReferenceExpansion)
  throws DOMException
{
  return new DomNodeIterator(root, whatToShow, filter,
                             entityReferenceExpansion, true);
}
项目:jvm-stm    文件:DomDocument.java   
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean expandEntities)
{
  return new DomNodeIterator(root, whatToShow, filter, expandEntities,
                             true);
}
项目:adalid    文件:XmiDomTree.java   
private void fillElementIdMap(TreeWalker tw) {
    Node n = tw.getCurrentNode();
    Element element = (Element) n;
    if (element.getAttributeNode(XmiTags.XMI_ID_TAG) != null) {
        XmiElement xmiElement = new XmiElement(element, this);
        elementIdMap.put(xmiElement.getXmiId(), xmiElement);
        //System.out.println("entity "+xmiElement.getNameTag()+" type "+xmiElement.getXmiType());
    }
    for (Node child = tw.firstChild();
        child != null;
        child = tw.nextSibling()) {
        fillElementIdMap(tw);
    }
    tw.setCurrentNode(n);
}
项目:Push2Display    文件:AbstractDocument.java   
/**
 * <b>DOM</b>: Implements {@link
 * DocumentTraversal#createTreeWalker(Node,int,NodeFilter,boolean)}.
 */
public TreeWalker createTreeWalker(Node root,
                                   int whatToShow,
                                   NodeFilter filter,
                                   boolean entityReferenceExpansion)
    throws DOMException {
    return TraversalSupport.createTreeWalker(this, root, whatToShow,
                                             filter,
                                             entityReferenceExpansion);
}
项目:Push2Display    文件:TraversalSupport.java   
/**
 * Creates a new tree walker.
 */
public static TreeWalker createTreeWalker(AbstractDocument doc,
                                          Node root,
                                          int whatToShow, 
                                          NodeFilter filter, 
                                          boolean entityReferenceExpansion) {
    if (root == null) {
        throw doc.createDOMException
            (DOMException.NOT_SUPPORTED_ERR, "null.root",  null);
    }
    return new DOMTreeWalker(root, whatToShow, filter,
                             entityReferenceExpansion);
}
项目:marytts-lang-ar    文件:MaryInterfaceArIT.java   
@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);


   }