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

O

Olivier Wulveryck

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
(e-mail address removed)
 
A

Andrew Thompson

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
 

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,077
Latest member
SangMoor21

Latest Threads

Top