Problem with XPath JDOM: Always the same value returned when selecting different nodes.

Discussion in 'Java' started by Olivier Wulveryck, Sep 14, 2004.

  1. Problem with JDOM 1.0 and XPath
    -------------------------------

    Hello,

    I'm a newbie to JDOM and not so advance in Java.
    I've got a problem when using the implementation of the
    org.jdom.xpath.XPath API.

    Action: Doing a loop to get multiple nodes.
    For each node, try to get the TEXT node of a child

    Result: Always the same text is returned

    Infos: JDOM: version 1.0
    JRE: 1.4.2_05
    Windows 2000

    It sound like the xpath is keeping a value in memory somewhere and
    that this value is never released.
    Did I miss something with XPath?

    Here is what i'm doing

    ------------------------------ cut here ------------------------
    CLASS 1{
    public Vector getSupportedBusObjs()
    throws JDOMException
    {
    Vector temp = new Vector();
    SupportedBusObj sb;
    XPath xpath = null;
    Iterator iter;
    Iterator iter2;
    String debug;
    List bod;
    Namespace cw = Namespace.getNamespace("cw",
    "http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas");
    xpath = XPath.newInstance("//cw:ContainerConfig/cw:ConnectorConfig/cw:supportedBusinessObjects");
    this.mySupportedBusObjs = xpath.selectNodes(this.jdomDocument);
    iter = mySupportedBusObjs.iterator();

    while (iter.hasNext()) {
    Element currentElement = (Element)(iter.next());
    XMLOutputter fmt = new XMLOutputter();
    bod = currentElement.getChildren("boDetails", cw);
    iter2 = bod.iterator();

    while (iter2.hasNext()) {
    currentElement = (Element)iter2.next();
    debug = fmt.outputString(currentElement);
    System.out.println("<debug
    name=\"Connector.getSupportedBusObjs().currentElement\">" + debug +
    "</debug>");
    sb = new SupportedBusObj(currentElement);
    System.out.println("<debug comment=\"Liste des Bos ajoutés dans le
    vecteur\">" + sb.getNom() + "</debug>");
    temp.addElement(sb);
    sb = null;
    currentElement = null;
    }
    }
    return temp;
    }
    }
    ------------------------------ cut here ------------------------
    class SupportedBusObj{
    public String getNom() throws JDOMException
    {
    XPath xpath2 = XPath.newInstance("//cw:boDetails/cw:name");
    xpath.addNamespace("cw","http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas");
    System.out.println("<debug meth=\"SupportedBusObj.getNom().1\">" +
    this.toXMLString() + "</debug>");
    System.out.println("<debug meth=\"SupportedBusObj.getNom().2\">" +
    ((Element)xpath2.selectSingleNode(this.getSupportedBusObjElement())).getText()
    + "</debug>");
    this.setNom(((Element)xpath2.selectSingleNode(this.getSupportedBusObjElement())).getText());
    System.out.println("<debug meth=\"SupportedBusObj.getNom().3\">" +
    this.sNom + "</debug>");
    xpath2 = null;
    return this.sNom;
    }
    public String toXMLString()
    {
    if (this.supportedBusObjElement != null) {
    // Output the document, use standard formatter
    XMLOutputter fmt = new XMLOutputter();
    return fmt.outputString(this.supportedBusObjElement);
    } else {
    return "";
    }
    }
    }
    ------------------------------ cut here ------------------------
    Sample XML file:

    <?xml version="1.0" encoding="utf-8" standalone="no" ?>
    - <cw:ContainerConfig
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas"
    xmlns:tns="http://www.ibm.com/websphere/crossworlds/2002/HierarchicalProperties">
    - <cw:ConnectorConfig maxTranLevel="">
    - <cw:supportedBusinessObjects>
    - <cw:boDetails>
    <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired>
    </cw:boDetails>
    - <cw:boDetails>
    <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails>
    - <cw:boDetails>
    <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails>
    </cw:supportedBusinessObjects>
    ....
    ------------------------ Result of execution -------------------------
    <debug name="Connector.getSupportedBusObjs().currentElement"><cw:supportedBusinessObjects
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:boDetails> <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    </cw:supportedBusinessObjects></debug>
    <debug name="SupportedBusObj.elementSB()"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired>
    </cw:boDetails></debug>
    <debug meth="SupportedBusObj.getNom().1"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired>
    </cw:boDetails></debug>

    <debug meth="SupportedBusObj.getNom().2">CodaEnrichissement</debug>
    <debug meth="SupportedBusObj.getNom().3">CodaEnrichissement</debug>

    <debug comment="Liste des Bos ajoutés dans le
    vecteur">CodaEnrichissement</debug>
    <debug name="SupportedBusObj.elementSB()"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails></debug>
    <debug meth="SupportedBusObj.getNom().1"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails></debug>

    <debug meth="SupportedBusObj.getNom().2">CodaEnrichissement</debug>
    <debug meth="SupportedBusObj.getNom().3">CodaEnrichissement</debug>

    <debug comment="Liste des Bos ajoutés dans le
    vecteur">CodaEnrichissement</debug>
    <debug name="SupportedBusObj.elementSB()"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails></debug>
    <debug meth="SupportedBusObj.getNom().1"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired>
    </cw:boDetails></debug>

    <debug meth="SupportedBusObj.getNom().2">CodaEnrichissement</debug>
    <debug meth="SupportedBusObj.getNom().3">CodaEnrichissement</debug>

    <debug comment="Liste des Bos ajoutés dans le
    vecteur">CodaEnrichissement</debug>
    <debug name="SupportedBusObj.elementSB()"><cw:supportedBusinessObjects
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:boDetails> <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    </cw:supportedBusinessObjects></debug>
    <debug meth="SupportedBusObj.getNom().1"><cw:supportedBusinessObjects
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:boDetails> <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    </cw:supportedBusinessObjects></debug>

    <debug meth="SupportedBusObj.getNom().2">CodaEnrichissement</debug>
    <debug meth="SupportedBusObj.getNom().3">CodaEnrichissement</debug>

    <debug name="sbo" iter="1">CodaEnrichissement</debug>
    <debug name="Connector.getSupportedBusObjs().currentElement"><cw:supportedBusinessObjects
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:boDetails> <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_ENR_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails> <cw:name>FrCODA_SAS_FRN_JDBC</cw:name>
    <cw:isMappingRequired>false</cw:isMappingRequired> </cw:boDetails>
    <cw:boDetails><cw:name>SuperBOBOBOBOBOBOBOBOBOBOBOBOBOBOBOBOBOBO</cw:name><cw:isMappingRequired>true</cw:isMappingRequired></cw:boDetails></cw:supportedBusinessObjects></debug>
    <debug name="SupportedBusObj.elementSB()"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>CodaEnrichissement</cw:name>
    <cw:isMappingRequired>true</cw:isMappingRequired>
    </cw:boDetails></debug>
    <debug meth="SupportedBusObj.getNom().1"><cw:boDetails
    xmlns:cw="http://www.ibm.com/websphere/crossworlds/2002/ComponentSchemas">
    <cw:name>CodaEnrichissement</cw:name> <cw:isMappingRequired>true
    ....

    Olivier Wulveryck
    AtosOrigin Systems Integration
     
    Olivier Wulveryck, Sep 14, 2004
    #1
    1. Advertising

  2. On 14 Sep 2004 06:10:58 -0700, Olivier Wulveryck wrote:

    > System.out.println("<debug meth=\"SupportedBusObj.getNom().2\">" +


    Please note, Olivier, that your lines are
    far too long to reach news readers without
    word-wrap. This necessitates the reader to
    reconstruct the broken lines to see your
    example, and reduces their motivation to help.

    For tips on preparing examples for others, ..
    <http://www.physci.org/codes/sscce.jsp>

    HTH

    --
    Andrew Thompson
    http://www.PhySci.org/ Open-source software suite
    http://www.PhySci.org/codes/ Web & IT Help
    http://www.1point1C.org/ Science & Technology
     
    Andrew Thompson, Sep 14, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alastair Cameron
    Replies:
    1
    Views:
    7,423
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  2. Timo Nentwig

    selecting nodes between other nodes

    Timo Nentwig, Jun 16, 2004, in forum: XML
    Replies:
    1
    Views:
    414
    Patrick TJ McPhee
    Jun 17, 2004
  3. Tjerk Wolterink
    Replies:
    9
    Views:
    1,253
    Joris Gillis
    Feb 7, 2005
  4. DiTieM
    Replies:
    1
    Views:
    514
    Martin Honnen
    Feb 9, 2006
  5. Replies:
    1
    Views:
    582
    Soren Kuula
    Aug 24, 2006
Loading...

Share This Page