0

I am trying to get data from the below XML.

    <vehicle>
        <id>vehicle</id>
        <frame>
            <material>plastic</material>

When I read the data from the frame tag, how do i get the value of frame tag.

2 Answers 2

1

You should fetch only the "Frame" tags using doc.getElementsByTagName("frame") and then print the value of their child "Material" tags.

Sign up to request clarification or add additional context in comments.

1 Comment

You have to make some more changes. The method getFirstChild() returns a text element and not the material element. For every frame element, fetch the list of children nodes (using getChildNodes()), and then iterate over this list to find the material tag and retrieve its value.
0

frameList= doc.getElementsByTagName("material");

Should be

frameList= doc.getElementsByTagName("frame");

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.