You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
876 B
Java

Get element attribute
package com.ack.xml.dom;
import com.ack.util.XmlUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
import org.xml.sax.InputSource;
public class GetElementAttribute {
public static void main( String[] args ) throws Exception {
// create an input source for target document and parse it
InputSource is = new InputSource( "resources\\personal.xml" );
Document d = XmlUtil.getDocument( is );
// get all tags in the document with the name link
NodeList links = d.getElementsByTagName( "link" );
for( int i = 0; i < links.getLength(); i++ ) {
// for every link tag
Element link = (Element) links.item( i );
// print out its manager attribute value
System.out.println( "attribute value = " + link.getAttribute( "manager" ) );
}
}
}