IBM®
跳转到主要内容
    中国 [选择]    使用条款
 
 
Select a scope:Search for:    
    首页    产品    服务与解决方案     支持与下载    个性化服务    
跳转到主要内容

developerWorks 中国  >  XML  >

Effective XML processing with DOM and XPath in Java

Analysis of many projects yields advice and suggested code

developerWorks

    Element root    = doc.getDocumentElement();
    Node configNode = root.getFirstChild();
    NodeList childNodes = configNode.getChildNodes();
    for (int childNum = 0; 
	 childNum < childNodes.getLength(); 
	 childNum++) 
    {
      if ( childNodes.item(childNum).getNodeType() == Node.ELEMENT_NODE ) {
	Element child = (Element) childNodes.item( childNum ) ;
	if ( child.getTagName().equals( "header" ) ) {
	  // Do something with the header
	  System.out.print("Got a header!\n");
	}
      }
    }

Return to article

    关于 IBM 隐私条约 联系 IBM 使用条款