Returns an iterator over the children of the given element with the given tag name. : DOM Element « XML « Java Tutorial

Java Tutorial
1. Language
2. Data Type
3. Operators
4. Statement Control
5. Class Definition
6. Development
7. Reflection
8. Regular Expressions
9. Collections
10. Thread
11. File
12. Generics
13. I18N
14. Swing
15. Swing Event
16. 2D Graphics
17. SWT
18. SWT 2D Graphics
19. Network
20. Database
21. Hibernate
22. JPA
23. JSP
24. JSTL
25. Servlet
26. Web Services SOA
27. EJB3
28. Spring
29. PDF
30. Email
31. J2ME
32. J2EE Application
33. XML
34. Design Pattern
35. Log
36. Security
37. Apache Common
38. Ant
39. JUnit
Java
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Tutorial » XML » DOM Element 
33. 6. 30. Returns an iterator over the children of the given element with the given tag name.
import java.util.ArrayList;
import java.util.Iterator;

import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/*
  * JBoss, Home of Professional Open Source
  * Copyright 2005, JBoss Inc., and individual contributors as indicated
  * by the @authors tag. See the copyright.txt in the distribution for a
  * full listing of individual contributors.
  *
  * This is free software; you can redistribute it and/or modify it
  * under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2.1 of
  * the License, or (at your option) any later version.
  *
  * This software is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this software; if not, write to the Free
  * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
  * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
  */

public class Utils {


  /**
   * Returns an iterator over the children of the given element with
   * the given tag name.
   *
   @param element    The parent element
   @param tagName    The name of the desired child
   @return           An interator of children or null if element is null.
   */
  public static Iterator<Element> getChildrenByTagName(Element element,
                                              String tagName)
  {
     if (element == nullreturn null;
     // getElementsByTagName gives the corresponding elements in the whole 
     // descendance. We want only children

     NodeList children = element.getChildNodes();
     ArrayList<Element> goodChildren = new ArrayList<Element>();
     for (int i=0; i<children.getLength(); i++) {
        Node currentChild = children.item(i);
        if (currentChild.getNodeType() == Node.ELEMENT_NODE && 
            ((Element)currentChild).getTagName().equals(tagName)) {
           goodChildren.add((Element)currentChild);
        }
     }
     return goodChildren.iterator();
  }

}
33. 6. DOM Element
33. 6. 1. Create a new element
33. 6. 2. Create Empty DOM Document
33. 6. 3. Add Text object to an Element.
33. 6. 4. Add a new element to the given parent
33. 6. 5. Add an entity to a specified Element.
33. 6. 6. Build a QName from the element name
33. 6. 7. Get the name of this element
33. 6. 8. Get the next sibling with the same name and type
33. 6. 9. Copy an XML document
33. 6. 10. Create New Element And Set Attribute
33. 6. 11. Find All Elements By Tag Name Name Space
33. 6. 12. Find Element And Set Or Create And Set
33. 6. 13. Get Element Boolean Value
33. 6. 14. Get Element Date Value
33. 6. 15. Get Element Float Value
33. 6. 16. Get Element Int Value
33. 6. 17. Get Element Long Value
33. 6. 18. Get Element QName
33. 6. 19. Get Element String Value
33. 6. 20. Get Element Text
33. 6. 21. Get Elements by parent element
33. 6. 22. Get First Element
33. 6. 23. Get Next Element
33. 6. 24. Get the first element child.
33. 6. 25. Return the first element child with the specified qualified name.
33. 6. 26. Find Element Or Container
33. 6. 27. Returns the text of the element
33. 6. 28. Return child elements with specified name.
33. 6. 29. Return the first named Element found. Null if none.
33. 6. 30. Returns an iterator over the children of the given element with the given tag name.
33. 6. 31. Moves the content of the given element to the given element
33. 6. 32. Return the next sibling with a given name and type
33. 6. 33. Returns the concatenated child text of the specified node.
33. 6. 34. Finds and returns the first child element node.
33. 6. 35. Finds and returns the first child node with the given name and attribute name, value pair.
33. 6. 36. Finds and returns the last child element node.
33. 6. 37. Finds and returns the last child node with the given name and attribute name, value pair.
33. 6. 38. Finds and returns the next sibling element node.
33. 6. 39. Finds and returns the next sibling node with the given name and attribute name, value pair.
33. 6. 40. Document To String
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.