Retrieving Information from XML Tree Documents

When you have parsed a document into a JadeXMLDocument object, you can search it to select the parts in which you are interested. If you know the names of specific elements in the tree, you can retrieve them using the JadeXMLDocument and JadeXMLElement classes methods. For example, the JadeXMLDocument::findElementsByTagName method retrieves all elements in the document with a specified name.

As the JadeXMLDocument class getElementByTagName, getElementByTagNameNS, getElementsByTagName, and getElementsByTagNameNS methods and the JadeXMLElement class getAllElementsByTagNameNS and getAllElementsByTagName methods scan sequentially to locate requested elements, they always returned requested elements in document sequence but may be relatively slow.

To improve performance, you can use the JadeXMLDocument class findElementByNameNS, findElementByTagName, findElementsByNameNS, and findElementsByTagName methods and the JadeXMLElement class findAllElementsByNameNS and findAllElementsByTagName methods to retrieve elements more directly through a collection, using the collection sequence. JADE fully supports the use of a mixture of the document and collection sequence methods to locate the requested elements.

The collection sequence methods provide a performance boost only if a localName or tagName parameter value is explicitly specified in the calling parameters. If you specify "*" in the localName or tagName parameter, the access method reverts to the functionality and performance of the document sequence methods to locate the requested elements.

The code in the following example uses these methods to search the library document and list all books with a specified author.

listBooks(doc: JadeXMLDocument; authorName: String);
vars
    books : JadeXMLElementArray;
    book  : JadeXMLElement;
begin
    create books;
    doc.findElementsByTagName('book', books);
    foreach book in books
        where book.getElementByTagName('author').text = authorName do
        write book.getElementByTagName('title').text;
    endforeach;
    delete books;
end;