[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: XML Designing Problems.


xerces selectsinglenode
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@x...>
> To: "Rajesh AVRS" <rajesh.ram@w...>
> Sent: Friday, February 08, 2002 6:14 PM
> Subject: Re:  XML Designing Problems.
> 
> 
> 
>>2/8/2002 4:42:18 AM, "Rajesh AVRS" <rajesh.ram@w...> 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
> 
> 



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.