1

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.

1
  • Isn't the name of the attribute "name" and the value "clusterSize"? Commented Feb 27, 2018 at 1:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.