[jdom-interest] direct access to an arbitrary element----can I do this??
Ladhani, Dilip
dladhani at gltg.com
Fri May 3 10:10:40 PDT 2002
Thanks Kevin,
That seems to be a good strategy.
I will definitely use it if there is no "getbyTagName()"" kinda method. Appreciate the quick response.
I am not worried about an element not being present as the vendor has a standadized xml.
Don't you think we should have a helper method like this.
-----Original Message-----
From: Kevin.Bedell at sunlife.com [mailto:Kevin.Bedell at sunlife.com]
Sent: Fri 5/3/2002 12:07 PM
To: jdom-interest at jdom.org
Cc:
Subject: Re: [jdom-interest] direct access to an arbitrary element----can I do this??
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.
---------------------------------------------------------------------------
_______________________________________________
To control your jdom-interest membership:
http://lists.denveronline.net/mailman/options/jdom-interest/youraddr@yourhost.com
More information about the jdom-interest
mailing list