Headline

A reuseable abstraction for traversal

Illustration

Consider the following Language:Java code from Contribution:xpathAPI which invokes an Language:XPath processor to retrieve all salary nodes so that they can be totaled:

public class Total {

    public static double total(Document doc) 
        throws Exception {

        // The aggregation variable 
        double total = 0;

        // Get the matching elements
        NodeList nodelist = XPathAPI.selectNodeList(doc, "//salary");

        // Process the elements in the nodelist
        for (int i=0; i<nodelist.getLength(); i++) {
            // Get element
            Element elem = (Element)nodelist.item(i);
            total += Double.parseDouble(elem.getTextContent());
        }
        return total;
    }
}

Specifically, the XPath API is invoked like this:

        NodeList nodelist = XPathAPI.selectNodeList(doc, "//salary");

The descendants axis of XPath (see "//") is leveraged here. This axis can be viewed as the provision of a traversal scheme.


There are no revisions for this page.

User contributions

    This user never has never made submissions.

    User edits

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.

    Syntax for editing wiki

    For you are available next options:

    will make text bold.

    will make text italic.

    will make text underlined.

    will make text striked.

    will allow you to paste code headline into the page.

    will allow you to link into the page.

    will allow you to paste code with syntax highlight into the page. You will need to define used programming language.

    will allow you to paste image into the page.

    is list with bullets.

    is list with numbers.

    will allow your to insert slideshare presentation into the page. You need to copy link to presentation and insert it as parameter in this tag.

    will allow your to insert youtube video into the page. You need to copy link to youtube page with video and insert it as parameter in this tag.

    will allow your to insert code snippets from @worker.