Re: RE: parse the child elements of an element
Arathi Arjun <[email protected]> Thu, 23 Oct 2003 00:27:17 -0400
| Newsgroups | gmane.text.xml.sax.general |
|---|---|
| Message-ID | <[email protected]> |
Hi,
In the following XML file:
<?xml-stylesheet href="mystyle.css" type="text/css"?>
<dealership>
<automobile make="Buick" model="Century" color="blue">
<options>
<option>convertible</option>
<option>CD Player</option>
</options>
</automobile>
<ship make="sailboat" color="red">
</ship>
</dealership>
If I want to output the element name and attributes of
ship only and ignore automobile with all its child elements..
can I create a filter class that extends XMLFilterImpl
and say
XMLReader parser;
try
{
parser =
(XMLReader)Class.forName(PARSER_NAME).newInstance();
filter.setParent(parser);
filter.parse(XML-FILE);
}
and override
public void startElement(String namespaceURI, String localName,
String qName, Attributes atts)
{
if(localName.equals("automobile"))
endElement(namespaceURI,localName,qName);
else{
System.out.println("Start element: " + localName);
for (int i = 0; i < atts.getLength(); i++) {
String name = atts.getLocalName(i);
String value = atts.getValue(i);
System.out.println("Attribute: " + name);
System.out.println("Value: " + value);
}
}
}
That does not skip the child-elements of automobile though.
How do I skip the child elements as well....
Thanks,
Arathi
________________________________________________
Get your own "800" number
Voicemail, fax, email, and a lot more
http://www.ureach.com/reg/tag
---- On Wed, 22 Oct 2003, [email protected] ([email protected])
wrote:
> XSL transform using value-of element where select attribute
absolutely
> addresses specific element.
>
> > Hi,
> > Given an XML document how do you using SAX2 only output
the
> > child elements of a specified element and ignore the other
> > elements.
> > -Arathi
>
>
>
-------------------------------------------------------
This SF.net email is sponsored by: The SF.net Donation Program.
Do you like what SourceForge.net is doing for the Open
Source Community? Make a contribution, and help us add new
features and functionality. Click here: http://sourceforge.net/donate/
_______________________________________________
List: [email protected]
See: http://www.saxproject.org
https://lists.sourceforge.net/lists/listinfo/sax-users