C ++ Builder XE2,TXMLDocument'禁止使用DTD' [英] C++ Builder XE2, TXMLDocument 'DTD is prohibited'
问题描述
当我尝试使用DTD读取XML文档(Eagle文件)时,出现错误消息:
When I try to read an XML document (eagle file) with an DTD I get the error:
项目xx引发了异常类EDOMParserError,消息为'DTD为禁止"
Project xx raised exception class EDOMParserError with message 'DTD is prohibited'
XML标头看起来像这样:
The XML header looks like this:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE eagle SYSTEM "eagle.dtd">
如果我删除第二行...
If I remove the second line...
<!DOCTYPE eagle SYSTEM "eagle.dtd">
...一切正常.
经过一番谷歌搜索之后,似乎MSXML解析器将名为"prohibitDTD"的选项默认情况下设置为 true (在早期版本中为false).
After some googling it seems like the MSXML parser have an option called ´prohibitDTD´ set to true by default (in earlier versions it was false).
但是,似乎不可能从TXMLDocument类中将此选项设置为false.一种解决方案似乎是.pas库的重新编译,或者由我自己使用CoCreateInstance()创建接口.
However it seems not possible to set this option to false from the TXMLDocument class. One solution seems to be a recompile of the .pas library or to create the interface on my own with CoCreateInstance().
我看到的所有示例都在Delphi中,并且我有很多技巧可以将它们转换为C ++ Builder.
All examples I have seen out there are in Delphi and I'm having dificulties to trasnlate these to C++ Builder.
有人知道如何使用C ++ Builder XE2读取DTD XML文档吗?
Does anyone know how to read a DTD XML document with C++ Builder XE2?
我的示例代码...
#include <xmldoc.hpp>
_di_IXMLNode XMLObject;
TXMLDocument *XMLDocument = new TXMLDocument(this);
XMLDocument->LoadFromFile(fileName); // <----- Exception EDOMParserError
XMLObject = XMLDocument->DocumentElement;
谢谢...
推荐答案
XE2针对此问题引入了本机解决方案:存在名为 Xml.Win.msxmldom.hpp中声明的docwiki.embarcadero.com/Libraries/zh-CN/Xml.Win.msxmldom.MSXML6_ProhibitDTD"rel =" noreferrer>
MSXML6_ProhibitDTD
代码>.您可以先将其设置为 false
,然后再将数据加载到 TXMLDocument
中:
XE2 introduced a native solution to this very problem: there is a global bool
variable named MSXML6_ProhibitDTD
declared in Xml.Win.msxmldom.hpp
. You can set it to false
before loading data into TXMLDocument
:
#include <xmldoc.hpp>
#include <msxmldom.hpp>
MSXML6_ProhibitDTD = false;
TXMLDocument *XMLDocument = new TXMLDocument(this):
XMLDocument->LoadFromFile(fileName);
_di_IXMLNode XMLObject = XMLDocument->DocumentElement;
附带说明:像这样动态创建 TXMLDocument
实例通常不是一个好主意.最好改用 IXMLDocument
接口:
On a side note: it is generally not a good idea to create TXMLDocument
instances dynamically like this. It is better to use the IXMLDocument
interface instead:
#include <xmldoc.hpp>
#include <msxmldom.hpp>
MSXML6_ProhibitDTD = false;
_di_IXMLDocument XMLDocument = LoadXMLDocument(fileName);
_di_IXMLNode XMLObject = XMLDocument->DocumentElement;
这篇关于C ++ Builder XE2,TXMLDocument'禁止使用DTD'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!