Hello,
I'm trying to use XPathEvaluator Xalan-C_1_10_0-win32-msvc_60 and xerces-c-windows_2000-msvc_60.
InvoiceOperator(XalanDocument* invoiceXalan){
XPathEvaluator::initialize();
// We'll use these to parse the XML file.
XalanSourceTreeDOMSupport theDOMSupport;
XalanSourceTreeParserLiaison theLiaison(theDOMSupport);
// Hook the two together...
theDOMSupport.setParserLiaison(&theLiaison);
XalanDocumentPrefixResolver thePrefixResolver(invoiceXalan);
XPathEvaluator theEvaluator;
// OK, let's find the context node...
XalanNode* const theContextNode = theEvaluator.selectSingleNode(
theDOMSupport,
invoiceXalan,
XalanDOMString("/Bill").c_str(),
thePrefixResolver);
cout << theContextNode->getNodeName() << endl;
if (theContextNode)
{
// OK, let's evaluate the expression...
const XObjectPtr theResult(
theEvaluator.evaluate(
theDOMSupport,
theContextNode,
XalanDOMString("AddressPage/InvParty/Addr/@Name").c_str(),
thePrefixResolver));
assert(theResult.null() == false);
cout << "The string value of the result is:"
<< endl
<< theResult->str()
<< endl;
}
XPathEvaluator::terminate();
}
theContextNode is succefully created with the right node but theEvaluator.evaluate returns an empty string, although the attribute AddressPage/InvParty/Addr/@Name exists.
The document XalanDocument* invoiceXalan is create by an other class and cannot modify the creation of it.
The XML file is :
<Bill>
<AddressPage xml:lang="EN">
<InvParty VATRegNo="111">
<Addr Name="Wise" Line1="Mobile" Line2="River Str." Line3="13" City="Geopolis" Zip="0555" Country="Germany"/>
<FiCont>
<Account Num="1234" HolderName1="Wise" HolderName2="Mobile"/>
<Bank Code="9876" Name="Bandar Bank" Branch="Neverland"/>
</FiCont>
<CCContact Person="">
</CCContact>
</InvParty>
<BillAcc Desc="Nm_58" PayMeth="Cash" BillMedium="L1HTL" CopyNo="1" State="">
<Customer Id="1.146" SocSecNo="" DrivLicNo=""/>
<Addr Name="" Line1="Mr." Line2="test2 test2" Line3="" Line4="Street2 House no2" City="City2" Zip="12345" Country="France"/>
<FiCont>
<Account Num="" HolderName1="" HolderName2=""/>
<Bank Code="" Name="" Branch=""/>
</FiCont>
</BillAcc>
</AddressPage>
</Bill>
After I run the program this is the output:
start:
Bill
The string value of the result is:
Press any key to continue
end
It shoulbe like this:
start:
Bill
The string value of the result is:
Wise
Press any key to continue
end
Please add any observation because it might work.
Kind regards,
InvoiceOperator(DOMDocument* invoiceDOM){
XPathEvaluator::initialize();
XercesDOMSupport dom_support;
XercesParserLiaison parser_liaison;
XalanDocument *xalan_document = parser_liaison.createDocument(invoiceDOM, false, true);
XalanNode * root_context_node = xalan_document;
XalanElement *namespace_node = xalan_document->getDocumentElement();
const XalanDOMString expression("/Bill/AddressPage/InvParty/Addr/@Name");
DOMNode *target= 0;
XPathEvaluator evaluator;
const XalanNode* found = evaluator.selectSingleNode(
dom_support,
root_context_node,
expression.c_str(),
namespace_node);
cout << found->getNodeValue();
XPathEvaluator::terminate();
}
After hours of traing and stres it's working now.
Thanks for any help. I don't know if it's possible to close this post now.
Regards,
Narcis