OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] XML Designing Problems.

[ Lists Home | Date Index | Thread Index ]

Hi Rajesh,

I would suggest you to try out dom4j. http://www.dom4j.org/
It provides XPath support as well as a well designed java api on top of 
DOM.
This example of selecting nodes based on XPath is taken from the quick 
start guide: http://www.dom4j.org/guide.html

     public void bar(Document document) {
         List list = document.selectNodes( "//foo/bar" );

         Node node = document.selectSingleNode( "//foo/bar/author" );

         String name = node.valueOf( "@name" );
     }

Using your structure (changing the root element from XML to ROOT)
<ROOT>
     <XYZ> Value of xyz </XYZ>
     <Children1>
         <ABC> Value of Element1 </ABC>
         <XYZ> Value for this xyz </XYZ>
     </Children1>
</ROOT>

// selects all XYZ elements (like getElementsByTagName("XYZ"))
Node node = document.selectSingleNode( "//XYZ" );

// selects XYZ elements directly within Children1
Node node = document.selectSingleNode( "//Children1/XYZ" );

Good XPath reading:
http://www.zvon.org/xxl/XPathTutorial/General/examples.html
http://www.w3.org/TR/xpath

/Fredrik Lindgren


Rajesh AVRS wrote:

> Hi Mike,
> 
> Can you give me more inputs on XPath?  And what Xalan can do which Xerces
> can't?  Please enlighten me.
> 
> Rajesh
> ----- Original Message -----
> From: "Mike Champion" <mc@xegesis.org>
> To: "Rajesh AVRS" <rajesh.ram@wipro.com>
> Sent: Friday, February 08, 2002 6:14 PM
> Subject: Re: [xml-dev] XML Designing Problems.
> 
> 
> 
>>2/8/2002 4:42:18 AM, "Rajesh AVRS" <rajesh.ram@wipro.com> wrote:
>>
>>
>>>Now if I have this kind of design for the document the results will be
>>>unpredictable right?  I never know corresponding the which XYZ tag the
>>>
> value
> 
>>>has been returned.  Any suggestions on how I can modify my method so that
>>>the caller can say, get me the value of XYZ which is a child of the root
>>>element or something like that.
>>>
>>Use XPath.  I believe that it is in Xerces DOM Level 3 support, or you
>>
> could use Xalan.
> 
>>
>>
> 
> 
> ------------------------------------------------------------------------
> 
> **************************Disclaimer************************************
>       
> 
> 
> Information contained in this E-MAIL being proprietary to Wipro Limited
> is 'privileged' and 'confidential' and intended for use only by the
> individual or entity to which it is addressed. You are notified that any
> use, copying or dissemination of the information contained in the E-MAIL
> in any manner whatsoever is strictly prohibited.
> 
> 
> 
>  ********************************************************************
> 
> 
> 
> ------------------------------------------------------------------------
> 
> -----------------------------------------------------------------
> The xml-dev list is sponsored by XML.org <http://www.xml.org>, an
> initiative of OASIS <http://www.oasis-open.org>
> 
> The list archives are at http://lists.xml.org/archives/xml-dev/
> 
> To subscribe or unsubscribe from this list use the subscription
> manager: <http://lists.xml.org/ob/adm.pl>
> 
> Wipro_Disclaimer.txt
> 
> Content-Type:
> 
> text/plain
> Content-Encoding:
> 
> 7bit
> 
> 
> ------------------------------------------------------------------------
> Part 1.3
> 
> Content-Type:
> 
> text/plain
> 
> 






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS