Hi, I think that using Xerces the only possible approach is the one that you described, that is traversing the tree and making comparison on each node.
One alternative approach might be using XSLT: you can write an XSL that extracts from your XML only the information that is valuable for you. This may be a simple example: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format"> <xsl:template match="NAME"> NAME - <xsl:value-of select="."/> </xsl:template> <xsl:template match="URL"> URL - <xsl:value-of select="."/> </xsl:template> <xsl:template match="every"> every - <xsl:value-of select="."/> </xsl:template> <xsl:template match="increaseby"> increaseby - <xsl:value-of select="."/> </xsl:template> <xsl:template match="delay"> delay - <xsl:value-of select="."/> </xsl:template> </xsl:stylesheet> you may try out this with Xalan (OK this maybe a little out of topic on this mailing list, sorry): java org.apache.xalan.xslt.Process -IN prasad.xml -XSL prasad.xsl where prasad.xsl is the previous stylesheet and prasad.xml is your example the association to the XSL stylesheet: <?xml version="1.0" encoding="UTF-8"?> <?xml-stylesheet type="text/xsl" href="C:\archivio\xml_vari\prasad.xsl"?> <PAGE> <BUSCASE> <NAME>Books Set 1</NAME> <URLS> <URL><![CDATA[/servlet/book1?title=abc&author=Fowler]]></URL> <URL><![CDATA[/servlet/book2?title=xyz&author=Hunter]]></URL> <URL><![CDATA[/servlet/book3?title=pqrs&author=GOF]]></URL> </URLS> <OTHERS> <every>1</every> <increaseby>2</increaseby> <delay>10</delay> </OTHERS> </BUSCASE> </PAGE> I don't know if this approach suits your needs, anyway I hope it helps. Cheers, Marco Sbodio > -----Original Message----- > From: Moganna, Prasad [mailto:[EMAIL PROTECTED] > Sent: Friday, November 02, 2001 6:57 PM > To: [EMAIL PROTECTED] > Subject: Parsing a xml file and getting node name/values > > > Hi All, > > I have a xml file (short snippet as shown below) > > <PAGE> > <BUSCASE> > <NAME>Books Set 1</NAME> > <URLS> > > <URL><![CDATA[/servlet/book1?title=abc&author=Fowler]]></URL> > > <URL><![CDATA[/servlet/book2?title=xyz&author=Hunter]]></URL> > > <URL><![CDATA[/servlet/book3?title=pqrs&author=GOF]]></URL> > ....... > ..... > </URLS> > <OTHERS> > <every>1</every> > <increaseby>2</increaseby> > <delay>10</delay> > </OTHERS> > </BUSCASE> > ..... > .... > </PAGE> > > My requirement is, given the "BUSCAE" node handle, the > program should output > > > NAME - Books Set 1 > URL - /servlet/book1?title=abc&author=Fowler > URL - /servlet/book2?title=xyz&author=Hunter > URL - /servlet/book2?title=pqrs&author=GOF > every - 1 > increaseby - 2 > delay - 10 > > I can traverse through the tree and make a comparison on each > node's name > and type, > but that would end up in too many comparisons. Is there any > other way of > writing such a program, if anybody has written such a program > and would like > to share, > it would be of great help. > > BTW, there is a DTD for this xml file and the above file > snippet satisfies > the dtd. > > Thanks, > Prasad M > > --------------------------------------------------------------------- > 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]
