XALANC WIN32

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,

 

 

 

 

 

I solved the problem:
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值