user2304377
user2304377

Reputation: 31

XPath function:contains Error(if I use it)!

xml:

<Root>
   <MyNode>
         <Name>东方a96</Name>
         <Status>0</Status>
   </MyNode>
   <MyNode>
          <Name>西方b92</Name>
          <Status>0</Status>
    </MyNode>
    <MyNode>
          <Name>东方a88</Name>
          <Status>0</Status>
     </MyNode>
</Root>

Code:

#import <msxml3.dll> named_guids
using namespace MSXML2;

......
strPath = CString(_T("/Root/MyNode[contains(Name,'a')]"));
pNodeList = m_pXmlQueryDoc->selectNodes((_bstr_t)strPath); 
......

BTW:if i don't use xpath function, there is no error.I have tested some xpth function,only string function can use,ohers all error at selectNodes line.

My System: win8 x64 IDE:VC MFC of vs2012(Unicode Project)

Upvotes: 2

Views: 71

Answers (1)

Dimitre Novatchev
Dimitre Novatchev

Reputation: 243579

You need to add this to your code:

setProperty(BSTR strProp, VARIANT strVal);

where:

strProp 
    A BSTR string whose value is "SelectionLanguage".
strVal 
    A VARIANT string, whose value is  "XPath".

When not specified, the default is "XSLPattern" -- and this means that XPath isn't turned on at all.

For more information, read this:

http://msdn.microsoft.com/en-us/library/windows/desktop/ms754679(v=vs.85).aspx

Upvotes: 1

Related Questions