You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xerces.apache.org by Per Lundkvist <pe...@iconmedialab.co.uk> on 2001/03/15 11:22:06 UTC

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
per.lundkvist@iconmedialab.co.uk


---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-j-user-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-j-user-help@xml.apache.org