2

I the following format:

<Results>
   <Value type="range"> 45-50 </Value>
   <Value type="range"> 65-58 </Value>
   <Value type="range"> 76-80 </Value>
   <Value type="range"> 48-60 </Value>
</Results>

I want to extract get the type value which is range and also the number.

this is my java code snippet,

NodeList mNode = doc.getElementsByTagName("Value");
String elementAttr = nElement.getAttribute("type"); // here i get the attribute to be "range"

but i am not sure how to extract the actual range "45-50".

1
  • 1
    did you intend to leave the ending '"' ? Commented Feb 22, 2013 at 16:29

2 Answers 2

4

try

nElement.getTextContent().trim();
Sign up to request clarification or add additional context in comments.

Comments

2

This is what I use

public static String attributeText(Node node, String namedItem) {
        String retValue = null;
        Node attribute = node.getAttributes().getNamedItem(namedItem);
        if (attribute != null) {
            retValue = attribute.getNodeValue();
        }
        return retValue;
    }

Comments

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.