>From my experience (and as far as I can tell), no...you cannot set a limit
on what getElementsByTagName() returns.

One way to find the one tag you're looking for (and I'm not claiming that
this is an efficient way) is to cycle through the returned NodeList and
search for the parent element name ("product") of the particular 'name'
element that you want; disregard the rest.

The short answer is no - you can't limit it (as far as I know).

Brion Swanson
-------------
Software Engineer
Content Transformation
West Publishing Group
Rochester, NY 14694

-----Original Message-----
From: Per Lundkvist [mailto:[EMAIL PROTECTED]
Sent: Thursday, March 15, 2001 5:22 AM
To: [EMAIL PROTECTED]
Subject: Set level of recursing


Is there a possibility to set the level of recursing when looking for a tag?
I have a XML file with the following structure

<?xml version="1.0" encoding="UTF-8"?>
<product>
        <name>Blue car</name>
        <parts>
                <part id="1">
                        <name>Wheel</name>
                </part>
                <part id="2">
                        <name>Body</name>
                </part>
        </parts>
</product>

When I try to get the tag "name" for the product element I find all name
tags. I would like to get only the first one, not the ones embedded in the
part elements.

Here is a sample of the code I use:

DOMParser parser = new DOMParser();
parser.setFeature("http://xml.org/sax/features/validation";, true);
parser.setFeature("http://apache.org/xml/features/continue-after-fatal-error
", true);
parser.setErrorHandler(errorHandler);
parser.parse(xmlFile);
document = parser.getDocument();
NodeList products = document.getElementsByTagName("product");
Element product = (Element) products.item(0);
NodeList names = product.getElementsByTagName("name");

The names variable now contains three elements, but I would like it to
contain just one. Is that possible?

Thanks for any help

/per

Per Lundkvist
Icon Medialab
[EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to