如何在 Delphi 7 中使用 MSXML 6.0 创建 TXML 文档?

发布于 12-04 05:40 字数 80 浏览 1 评论 0原文

Delphi 7 发布时 MSXML 6.0 还不存在。是否可以将 Delphi 的 TXML 文档配置为使用 MSXML 6.0 而不是旧版本?

MSXML 6.0 didn't exist when Delphi 7 was released. Is it possible to configure Delphi's TXML Document to use MSXML 6.0 instead of the older versions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

赠我空喜2024-12-11 05:40:30

将以下代码添加到单元名称 uMSXMLVersion 或您选择的名称中,并将其添加到您的项目中

{----------------------------------------------------------------------------    
  Set Delphi's XMLDocument to use MSXML v6.0

  Usage:  Include unit in project "uses"-list and Delphi will automatically use
          MSXML v6.0 for TXmlDocument.
-----------------------------------------------------------------------------}
unit uMSXMLVersion;

interface

implementation

uses ActiveX, MSXML, MSXMLDOM;

function CreateDOMDocumentEx: IXMLDOMDocument;
const
  CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';
begin
  Result := nil;
  if CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IXMLDOMDocument, Result) <> S_OK then
  Result := CreateDOMDocument; //call the default implementation
end;

initialization
  MSXMLDOMDocumentCreate := CreateDOMDocumentEx;

end.

Add the below code to a unit name uMSXMLVersion or your name of choice and add it to your projects uses

{----------------------------------------------------------------------------    
  Set Delphi's XMLDocument to use MSXML v6.0

  Usage:  Include unit in project "uses"-list and Delphi will automatically use
          MSXML v6.0 for TXmlDocument.
-----------------------------------------------------------------------------}
unit uMSXMLVersion;

interface

implementation

uses ActiveX, MSXML, MSXMLDOM;

function CreateDOMDocumentEx: IXMLDOMDocument;
const
  CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';
begin
  Result := nil;
  if CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or
    CLSCTX_LOCAL_SERVER, IXMLDOMDocument, Result) <> S_OK then
  Result := CreateDOMDocument; //call the default implementation
end;

initialization
  MSXMLDOMDocumentCreate := CreateDOMDocumentEx;

end.
情话墙2024-12-11 05:40:30

msxmldom.pas 单元公开一个公共 MSXMLDOMDocumentCreate 挂钩,您可以为其分配自定义处理程序,例如:

uses
  ..., msxmldom;

const
  CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';

function CreateMSXML6Document: IXMLDOMDocument;
var
  Disp: IDispatch;
begin
  OleCheck(CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, Disp));
  Result := Disp as IXMLDOMDocument;
  if not Assigned(Result) then
    raise DOMException.Create('MSXML 6.0 Not Installed');
end;

initialization
  msxmldom.MSXMLDOMDocumentCreate := CreateMSXML6Document;

The msxmldom.pas unit exposes a public MSXMLDOMDocumentCreate hook that you can assign a custom handler to, eg:

uses
  ..., msxmldom;

const
  CLASS_DOMDocument60: TGUID = '{88D96A05-F192-11D4-A65F-0040963251E5}';

function CreateMSXML6Document: IXMLDOMDocument;
var
  Disp: IDispatch;
begin
  OleCheck(CoCreateInstance(CLASS_DOMDocument60, nil, CLSCTX_INPROC_SERVER or CLSCTX_LOCAL_SERVER, IDispatch, Disp));
  Result := Disp as IXMLDOMDocument;
  if not Assigned(Result) then
    raise DOMException.Create('MSXML 6.0 Not Installed');
end;

initialization
  msxmldom.MSXMLDOMDocumentCreate := CreateMSXML6Document;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文