Getting to an internal xml node

Posted on 2006-05-09
Last Modified: 2010-05-18
Hey experts,

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

            <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" />

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??
Question by:mte01
    LVL 86

    Accepted Solution

    String attribute = null;
    NodeList nodes = doc.getElementsByTagName("Z00000774");
    if (nodes.getLength() > 0) {
          attribute = ((Element)nodes.item(0)).getAttribute("desc");
    LVL 3

    Author Comment


    That did the trick..thanks for your help!
    LVL 86

    Expert Comment


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Suggested Solutions

    An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
    Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
    Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
    This video teaches viewers about errors in exception handling.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now