I'm trying to parse XML files that have elements that look like this below.
<bean id="SPEX"
parent="SPEXParent">
<constructor-arg name="delegate">
<bean id="delegateSPEX"
parent="delegateSPEXParent"
p:name="SPEXName)"
p:maximumClusters="1"
p:jobFlowRequest-ref="jobFlowRequestSPEX"/>
</constructor-arg>
<constructor-arg name="manifestEncryptionManager" ref="manifestEncryptionManager"/>
<constructor-arg name="emrClient" ref="emrClientFacade"/>
<constructor-arg name="displayName" value="SPEXDisplayName"/>
<constructor-arg name="description" value="SPEXDescription"/>
<constructor-arg name="customerIds">
<list><ref bean="spex"/></list>
</constructor-arg>
<constructor-arg name="clusterSize" ref="MediumSPEX"/>
</bean>
I need to grab the values under "bean id", "bean id" under "constructor-arg name="delegate", "p:name", "p:maximumClusters", "displayName", "description", and "clusterSize". What I have so far is :
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
Document doc = dBuilder.parse(customerFile);
doc.getDocumentElement().normalize();
NodeList poolList = doc.getElementsByTagName("bean");
and then I attempt to go through every node in the poolList with:
for (int i = 0; i < poolList.getLength(); i++) {
Node poolNode = poolList.item(i);
System.out.println(poolNode.getAttributes().getNamedItem("clusterSize")
}
but it's never able to find the elements. And I'm not sure how to get the nested "p:name", "p:maximumClusters", etc under the nested bean id. Can anyone point me in the right direction? Thank you.