How to read an attrbute of an XML tag?
Hi,
Can anybody comment onthe follwoing code what to add inorder to read an attribute of a tag?
*************************XML****************
<data-source type="org.apache.commons.dbcp.BasicDataSource" >
<set-property property="driverClassName" value="com.mysql.jdbc.Driver"/>
<set-property property="url" value="jdbc:mysql://localhost/cms"/>
<set-property property="username" value="root"/>
<set-property property="password" value="test"/>
<set-property property="maxActive" value="0"/>
<set-property property="maxWait" value="5000"/>
<set-property property="defaultAutoCommit" value="true"/>
<set-property property="defaultReadOnly" value="false"/>
</data-source>
*********************************************************
Java CODE:::::::::::::::::
DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
Document doc = docBuilder.parse (new java.io.File("some.xml");
doc.getDocumentElement ().normalize ();
System.out.println ("Root element of the doc is " +
doc.getDocumentElement().getNodeName());
NodeList listOfProperties = doc.getElementsByTagName("set-property");
Element sppty=(Element)listOfProperties;
System.out.println("ATTRIBUTE Property Value-->"+sppty.getAttribute("property"));
ABOVE CODE THROWS ME NULL POINTER EXCEPTION, pls correct me if am wrong?
BR,
Peace

