getElementsByTagName()不能处理DOMDOCUMENT60的特殊字符
getElementsByTagName() is not working with special characters for DOMDOCUMENT60
我试图从这里附加的XML文件(data.xml)获得一个特定的书id。这是工作良好---- getElementsByTagName(_bstr_t("book"))
但是当我搜索某本书的时候异常——getElementsByTagName(_bstr_t("book[@id='bk101']"))
此问题见于DOMDOCUMENT60。
我不知道为什么它不能处理特殊字符。有人遇到过这个问题或者有什么建议吗?
#include "stdafx.h"
#include<iostream>
#include "Msxml.h"
#import "msxml6.dll"
using namespace MSXML2;
#include "stdlib.h"
#include "stdio.h"
#include <string>
using namespace std;
void LoadXML()
{
HRESULT hr1, hr;
hr1 = CoInitialize(NULL); //without this, cocreateinstance returns null pointer.
_variant_t vaNodeVal("C://data.xml");
VARIANT var1 = vaNodeVal;
CComPtr<IXMLDOMDocument2> sSourceInputXml = 0;
hr = sSourceInputXml.CoCreateInstance(__uuidof(MSXML2::DOMDocument60));
int ii=10;
if (hr == S_OK && sSourceInputXml != NULL)
{
hr = sSourceInputXml->load(var1);
int err = GetLastError();
ii=20;
try
{
ii = 30;
CComQIPtr<MSXML2::IXMLDOMNodeList> xmlACPInput;
std::cout << "nworking";
xmlACPInput = sSourceInputXml->getElementsByTagName(_bstr_t("book[@id='bk101']")); //throwing exception
std::cout << "n not working";
long lCount = 0;
xmlACPInput->get_length(&lCount);
bool isACP = false;
if (lCount == 0)
{
isACP = false;
}
else
{
isACP = true;
}
}
catch (exception ex)
{
ii = 1101;
}
catch (...)
{
ii = 1100;
}
}
CoUninitialize();
}
int _tmain(int argc, _TCHAR* argv[])
{
LoadXML();
return 0;
}
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>
An in-depth look at creating applications
with XML.
</description>
</book>
<book id="bk102">
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
<description>
A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.
</description>
</book>
<book id="bk103">
<author>Corets, Eva</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
<description>
After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.
</description>
</book>
</catalog>
From https://msdn.microsoft.com/en-us/library/bb985161.aspx
因为表达式可以使用XPath 1.0或XSL模式语法方面,需要有一种方法来指定选择语言在使用这些api之前。保持向后兼容性现有代码,默认选择语言是XSL Patterns。来将当前选择语言更改为XPath,调用newsetProperty方法(参见IXMLDOMDocument2),使用SelectionLanguage属性名和值
DomDocument30的默认选择语言是XSL Patterns
,这是XPath 1.0
的非标准微软实现前身。
它隐式地支持使用带有getElementsByTagName方法的XSL模式。
由于DomDocument60不支持XSL Patterns
,它的默认选择语言是XPath
,并且它的getElementsByTagName方法严格要求一个名称而不是模式或查询。因此需要使用selectNodes方法使用XPath进行查询。
在DomDocument60中,相当于旧getElementsByTagName("book[@id='bk101']")
的是selectNodes("//book[@id='bk101']")
所以试试吧:
xmlACPInput = sSourceInputXml->selectNodes(_bstr_t("//book[@id='bk101']"));
- 编译要在英特尔Hyperscan中使用的.cc文件时出现问题
- 将gsl c++程序与"英特尔MKL"链接
- 使用英特尔 PIN 修改寄存器
- 使用英特尔内联函数将打包的 8 位整数乘以浮点数向量
- 如何使用英特尔 PIN 捕获阵列的所有负载?
- 库特<<恩德尔;不适用于打印 2D 阵列
- 库特无符号字符
- 英特尔 TBB 程序不会终止,可能会误用参考计数器
- GCC/CLang不同意模板模板参数的部分特化
- 与卡特琳娜一起卷曲C++失败并得到"Undefined symbols for architecture x86_64"
- 将"-01"替换为"-02" 英特尔编译器选项会导致 FPE 在较小的 for 循环行程计数中抛出
- 如何在贝尔曼福特算法中检测负循环?
- 我如何创建一个函数(),其中一帕雷米特是映射
- 特里树.无法访问内存
- 在 Azure DevOps 构建管道中使用英特尔C++编译器为 Linux 环境构建C++代码
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 康斯特指针C++斯特劳斯特鲁普
- 如何要求 macports 用英特尔编译器包装 openmpi?
- 实施英特尔实感和 SDL2 时出现问题
- OpenGL 片段着色器未在英特尔 HD 4000 显卡上编译