今天在VS2003下使用xerces解析XML时遇到如下编译错误:
“error C2872: “DOMDocument” : 不明确的符号”找了好久没有找到问题所在,最后在网上查找资料说是MSXML和xerces中存在DOMDocument重定义问题。而我的工程中包含如下头文件:
#include "Basefun.h"
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
其中"Basefun.h"中包含有#include <windows.h>如下语句。于是将上面包含顺序修改为:
#include <xercesc/util/OutOfMemoryException.hpp>
#include <xercesc/parsers/XercesDOMParser.hpp>
#include <xercesc/framework/MemBufInputSource.hpp>
#include "Basefun.h"
也即将#include <windows.h>头文件放到xerces相关头文件后面,问题就解决了。
下面是在网上搜集的关于这个问题的相关描述:
winsock.h
windows.h
ole2.h
objbase.h
urlmon.h
msxml.h
有两种方法了:
1、解决方法可以用 #undef DomDocument
例如你在test.cpp中包含有window.h 和包含了xerces的文件test.h
那么可以这样定义来解决问题:
#include <windows.h>
#undef DomDocument
#include "test.h"
2、typedef xercesc_2_7::DOMDocument DOMDOC
用DOMDOC 来代替DomDocumen