tags:

views:

60

answers:

1

Need to select all nodes from the path a/b/c as NodeList from a Document using getElementsByTagName() . How do i provide path of node as input?

eg: -

<root>
    <a>
        <b>
            <c>1</c>
            <c>2</c>
            <c>3</c>
            <c>4</c>
            <c>5</c>
            <c>6</c>
        </b>
    </a>
</root>

need to select all 'c' nodes from the path a/b/c . How can I achieve this. Directly selecting c is an option, but to avoid ambiguity if more 'c's are present, I need to give the path. How do I achieve this?

+4  A: 

Take a look at the Java XPathAPI. You probably want to specify an XPath of /root/a/b to specify all the <c/> nodes in the above hierarchy.

Brian Agnew