Getting to an internal xml node

Hey experts,

I want to get the value of the "desc" attribute of node Z00000774 in the following xml file (using org.w3c.dom):

<BillingSystem>
    <BillingSystemMetaData>
     <Transform>
      <MappingCodes>
        <ChargeCodes>
            <Z00000774 desc="TELEPHONE LINE CLASSIC - SUBSCRIPTION" />
            <Z00001059 desc="PHONE MAESTRO 300 ANTHRACITE V1" />
            <Z00001111 desc="FIXED RELOCATION COSTS" />
            <Z00001236 desc="RANGE OF 10 CALLING NUMBERS (DDI)" />
            <Z00003537 desc="RESTRICTION CONSULTEL SERVICE (090)" />
            <Z00004014 desc="RANGE OF 100 NUMBERS (DDI)" />
            <Z00006633 desc="NUMBER RETENTION FOR DDI" />
         </ChargeCodes>
       </MappingCodes>
    </Transform>
  </BillingSystemMetaData>
</BillingSystem>

I am trying  resultCode = doc.getElementsByTagName("Z00000774").item(0).getAttributes().item(0).getNodeValue();
but it's not working, any help on the correct java syntax that gets the value??
LVL 3
mte01Asked:
Who is Participating?
 
CEHJCommented:
String attribute = null;
NodeList nodes = doc.getElementsByTagName("Z00000774");
if (nodes.getLength() > 0) {
      attribute = ((Element)nodes.item(0)).getAttribute("desc");
}
      
0
 
mte01Author Commented:
>>CEHJ

That did the trick..thanks for your help!
0
 
CEHJCommented:
:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.