• MSDN XPath


    • IXMLDOMDocument *pXMLDoc = NULL
          IXMLDOMNode *pNode = NULL
          BSTR     bstr = NULL;  
          VARIANT_BOOL status; 
          VARIANT var; 
          HRESULT hr; 
          int i = 0
       
          CoInitialize(NULL); 
          VariantInit(&var); 
       
          hr = CoCreateInstance(CLSID_DOMDocument, NULL,  
              CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER 
              , IID_IXMLDOMDocument, (LPVOID*)&pXMLDoc); 
          if (!pXMLDoc || pXMLDoc==NULL) { 
              iItems = -1; 
              // DOM creation failed! 
          } 
       
          VariantClear(&var); 
          var = bstr2var(_bstr_t("d:\book.xml")); 
          hr = pXMLDoc->load(var, &status); 
          if (status!=VARIANT_TRUE) { 
              iItems = -2; 
              // unable to load file! 
          } 
       
          pXMLDoc->selectSingleNode(L"catalog/book[last()]/author", &pNode);       
       
          if (pNode!=NULL) { 
              pNode->get_text(&bstr); 
              CString u; 
              u.Format("%s", (LPCTSTR)(_bstr_t)bstr); 
              AfxMessageBox(u); 
          } else { 
              AfxMessageBox("pNode = NULL!"); 
          } 

      The result of above expression is pNode = NULL.

      I use VC++ 6.0 and MSXML2 (just curious, I also tried to use VC 2005 and MSXML6 with similar code as above, but the result is the same)

      Did I miss something?

      Thanks!

      -nb: I test the expression using BIT-101 (http://www.bit-101.com/xpath/) and works fine.


      Tuesday, November 11, 2008 1:40 PM
      Avatar of Houari
      15 Points

    All replies

    • To use XPath you have to set the property "SelectionLanguage" to "XPath". 

      pXMLDoc->setProperty("SelectionLanguage", "XPath");

      To be able to do this, you have to use the IXMLDOMDocument2 interface instead of IXMLDOMDocument.

      Read more about How To Use XPath Queries in MSXML.
  • 相关阅读:
    coolify heroku & netlify 可选开源方案
    signoz reader 接口定义
    minio 纠删码测试
    minio 系统自动纠删码处理算法简单说明
    apm + tracing 一些开源工具参考资料
    minio 4*4 集群 故障测试
    mimir grafana 部署模式
    temporal 开源微服务编排引擎
    nocodb 核心入口依赖
    hammerdb 数据库负载以及性能测试工具
  • 原文地址:https://www.cnblogs.com/eaglezzb/p/4176459.html
Copyright © 2020-2023  润新知