Java Mailing List Archive

http://www.junlu.com/

Home » Home (12/2007) » JDOM User »

[jdom-interest] Question about using Xpath whilst using jdom beta 10

Bush, Chris

2004-09-01

Replies:

Hi

I am new to Jdom and have a question. I am trying use the following code to
extract out "legIds" from the attached xml. However, I seem to get the same
legId value twice, rather than the 2 distinct values I am expecting. Am I
doing something wrong ? The output I expect is

Leg = leg1
Legid = 00066786
Leg = leg2
Legid = 00066787

But I get this instead :

Leg = leg1
Legid = 00066786
Leg = leg2
Legid = 00066786

Thanks
Chris Bush

private void test( org.jdom.Document doc ) throws Exception
{
   org.jdom.xpath.XPath path =
org.jdom.xpath.XPath.newInstance("//swapLeg");
   org.jdom.xpath.XPath legpath =
org.jdom.xpath.XPath.newInstance("//legId");

   List elements = path.selectNodes(doc);

   for ( int i = 0; i < elements.size(); i++ )
   {
      org.jdom.Element e = (org.jdom.Element)elements.get(i);

      System.out.println(" Leg = " + e.getAttributeValue("legId") );

      System.out.println(" Legid = " + legpath.valueOf(e));
   }
}

The xml is attached :

<<103416L.xml>>



------------------------------------------------------------------------------
This message is intended only for the personal and confidential use of the
designated recipient(s) named above. If you are not the intended recipient of
this message you are hereby notified that any review, dissemination,
distribution or copying of this message is strictly prohibited. This
communication is for information purposes only and should not be regarded as
an offer to sell or as a solicitation of an offer to buy any financial
product, an official confirmation of any transaction, or as an official
statement of Lehman Brothers. Email transmission cannot be guaranteed to be
secure or error-free. Therefore, we do not represent that this information is
complete or accurate and it should not be relied upon as such. All
information is subject to change without notice.

Attachment: 103416L.xml
_______________________________________________
To control your jdom-interest membership:
http://www.jdom.org/mailman/options/jdom-interest/youraddr@(protected)
©2008 junlu.com - Jax Systems, LLC, U.S.A.