Hello,
I try to carry out a request xpath on the return of a preceding request
(selectNodeList) but the result is not that awaited: it would seem that
the context is not taken into account in the second request. I always
obtain the same result independently of the context.
I join an example of file xml and an extract of the source code.
Can you explain me where is located my error? I acknowledge more not to
understand…
Thank you
Stephane
This is the xml file :
<racine>
<noeud1 attribut="z1">
<noeud2 attr="xx">
<noeud11 attr1="val1" attr2="att11"/>
<noeud11 attr1="val2" attr2="att12"/>
<noeud11 attr1="val3" attr2="att13"/>
</noeud2>
<noeud2 attr="xxxx">
<noeud11 attr1="val1" attr2="att21"/>
<noeud11 attr1="val2" attr2="att22"/>
<noeud11 attr1="val3" attr2="att23"/>
</noeud2>
<noeud2 attr="xxxxxx">
<noeud11 attr1="val1" attr2="att31"/>
<noeud11 attr1="val2" attr2="att32"/>
<noeud11 attr1="val3" attr2="att33"/>
</noeud2>
</noeud1>
<noeud1 attribut="z2">
<noeud2 attr="xx">
<noeud11 attr1="val1" attr2="att11"/>
<noeud11 attr1="val2" attr2="att12"/>
<noeud11 attr1="val3" attr2="att13"/>
</noeud2>
<noeud2 attr="xxxx">
<noeud11 attr1="val1" attr2="att21"/>
<noeud11 attr1="val2" attr2="att22"/>
<noeud11 attr1="val3" attr2="att23"/>
</noeud2>
<noeud2 attr="xxxxxx">
<noeud11 attr1="val1" attr2="att31"/>
<noeud11 attr1="val2" attr2="att32"/>
<noeud11 attr1="val3" attr2="att33"/>
</noeud2>
</noeud1>
</racine>
This is my code :
...
const string xEvolZone = "/racine/[EMAIL PROTECTED]'z1']/noeud2";
XPathEvaluator theEvaluator;
// racine du document
XalanElement* racine = document->getDocumentElement();
if (racine == 0) {
throw (exception("Fichier non valide"));
}
else {
// evaluation de la requete
NodeRefList noeuds;
theEvaluator.selectNodeList(noeuds, *theDOMSupport, racine,
XalanDOMString(xEvolZone.c_str()).c_str(), *thePrefixResolver);
// parcours des resultats
for (unsigned int i = 0; i < noeuds.getLength(); i++) {
XalanNode* noeud = noeuds.item(i);
XalanDOMString val;
XalanDOMString::CharVectorType tmp;
const int typ = noeud->getNodeType();
// lecture de l'attribut attr
const XalanNamedNodeMap* attr = noeud->getAttributes();
XalanNode* date = attr->getNamedItem(TranscodeFromLocalCodePage("attr"));
val = date->getNodeValue();
val.transcode(tmp);
string sAttr = c_str(tmp);
// lecture de la valeur
const string xValParam = "//[EMAIL PROTECTED]'val2']/@attr2";
XalanNode* valeur = theEvaluator.selectSingleNode(*theDOMSupport, noeud,
XalanDOMString(xValParam.c_str()).c_str(), *thePrefixResolver);
string str;
val = valeur->getNodeName();
val.transcode(tmp);
str = c_str(tmp); // PB : always = attr2
val = valeur->getNodeValue();
val.transcode(tmp);
str += c_str(tmp); // PB : always = att12
...
}
}