[jdom-interest] direct access to an arbitrary element----can I do this??

Kevin.Bedell at sunlife.com Kevin.Bedell at sunlife.com
Fri May 3 09:07:46 PDT 2002





I'd do that like this:

            Element     root = doc.getRootElement();

            Element     pqr_Element = root.getChild("def").getChild("ghi").getChild("mno").getChild("pqr");
            Element     rst_Element = root.getChild("def").getChild("ghi").getChild("mno").getChild("rst");
            Element     uvw_Element = root.getChild("def").getChild("ghi").getChild("mno").getChild("uvw");

Not sure about XPATH support - it may be cleaner. Not sure if it's supported.

Be careful - if one of the intermediate getChild() calls returns null, you'll throw NullPointerException.

FWIW-
Kevin






"Ladhani, Dilip" <dladhani at gltg.com>@jdom.org on 05/03/2002 11:49:58 AM

Sent by:  jdom-interest-admin at jdom.org


To:   <jdom-interest at jdom.org>
cc:    (bcc: Kevin Bedell/Systems/USHO/SunLife)
Subject:  [jdom-interest] direct access to an arbitrary element----can I do
      this??


Hey guys,

I have a simple operation to do. I am not sure how I can do this using
Jdom. I have an XML that I get from on of our vendors. It kinda looks like
this
<?xml version="1.0" encoding="ISO-8859-1" ?>
<abc>
     <def>
           <ghi>
               <jkl>
                      <mno>
                                <pqr>1111</pqr>
                                <rst>2222</rst>
                                <uvw>3333</uvw>
                       </mno>
               </jkl>
           </ghi>
     </def>
</abc>

Can I directly read the data in the tags pqr, rst, uvw etc or do I have to
keep doing getchild() until I reach the tag mno to do anything meaningful.
In short how can I access a tag somewhere in the xml tree by tag name.


Thanks, Your help is appreciated.

_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com



---------------------------------------------------------------------------
This e-mail message (including attachments, if any) is intended for the use
of the individual or entity to which it is addressed and may contain
information that is privileged, proprietary , confidential and exempt from
disclosure.  If you are not the intended recipient, you are notified that
any dissemination, distribution or copying of this communication is
strictly prohibited.  If you have received this communication in error,
please notify the sender and erase this e-mail message immediately.
---------------------------------------------------------------------------




More information about the jdom-interest mailing list