- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一些使用 Delphi 的 TXMLDocument 类的工作代码,并使用 TransformNode 方法执行 XSLT 转换。
但是,我需要启用 XSLT Javascript 函数( <msxml:script>
标签)并且 - 经过多次谷歌搜索 - 这意味着我需要设置 AllowXsltScript
IXMLDOMDocument2
的属性(property)为真。
http://msdn.microsoft.com/en-us/library/windows/desktop/ms760290(v=vs.85).aspx
我已经成功实现了这一点 - 但只能通过修改 Delphi 库函数的源代码 CreateDOMDocument
在msxmldom.pas
.
function CreateDOMDocument: IXMLDOMDocument;
var doc :IXMLDOMDocument2;
begin
doc := TryObjectCreate([CLASS_DOMDocument60, CLASS_DOMDocument40, CLASS_DOMDocument30,
CLASS_DOMDocument26, msxml.CLASS_DOMDocument]) as IXMLDOMDocument2;
if not Assigned(doc) then
raise DOMException.Create(SMSDOMNotInstalled);
doc.setProperty('AllowXsltScript', true); // Allow XSLT scripts!!
Result := doc;
end;
显然这远不能令人满意 - 那么如何在不修改库代码的情况下访问 IXMLDOMDocument2 对象?
最佳答案
您可以通过 MSXMLDOMDocumentCreate
变量重写创建函数:
unit Unit27;
interface
uses
xmldoc, xmlintf, msxml, msxmldom, Forms, SysUtils,
ActiveX, ComObj, XmlDom, XmlConst,
Windows, Messages, Classes, Controls, StdCtrls;
type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TryObjectCreate(const GuidList: array of TGuid): IUnknown;
var
I: Integer;
Status: HResult;
begin
Status := S_OK;
for I := Low(GuidList) to High(GuidList) do
begin
Status := CoCreateInstance(GuidList[I], nil, CLSCTX_INPROC_SERVER or
CLSCTX_LOCAL_SERVER, IDispatch, Result);
if Status = S_OK then Exit;
end;
OleCheck(Status);
end;
function CreateDOMDocument2: IXMLDOMDocument;
var
Doc2 : IXMLDOMDocument2;
begin
Doc2 := TryObjectCreate([CLASS_DOMDocument60, CLASS_DOMDocument40, CLASS_DOMDocument30,
CLASS_DOMDocument26, msxml.CLASS_DOMDocument]) as IXMLDOMDocument2;
if not Assigned(Doc2) then
raise DOMException.Create(SMSDOMNotInstalled);
Doc2.setProperty('AllowXsltScript', true);
Result := Doc2;
end;
procedure TForm1.FormCreate(Sender: TObject);
var
Doc : IXMLDocument;
begin
Doc := TXMLDocument.Create(nil);
Doc.LoadFromFile('c:\temp\test.xml');
end;
initialization
MSXMLDOMDocumentCreate := CreateDOMDocument2;
end.
关于delphi - 通过 TXMLDocument 访问 IXMLDOMDocument2?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17143805/
通过 C++ 使用 MSXML,当我调用 IXMLDOMDocument::save 时,空的 XML 元素将获得一个结束标记,如下所示: 但我希望它保存为: 我
令人惊讶的是 IXMLDOMDocument::selectNodes 没有按预期工作。我知道这是因为 xmlns="http://stackoverflow.com/questions/ask",但
我正在尝试调试代码中似乎是 XML 解析的问题。我已将其分离为以下代码片段: HRESULT CXmlDocument::Load(IStream* Stream) { CComVariant
我正在使用 IXMLDOMDocument::transformNode使用看起来有点像这样的 C++ 代码应用 XSLT 转换: CComPtr spXMLDoc; // load spXMLDoc
我正在使用 IXMLDomDocument 指针加载我的 XML。加载失败说 DTD 被禁止。找不到设置 ProhibitDTD 属性的函数。 例子: IXMLDOMDocument *pXMLDom
我正在 (VS2013) 上构建一个 GTK+ VS2010 项目配置,我正在尝试添加浏览文件夹功能(我想使用 native Windows 方式)。我正在使用以下代码: #include #inc
我是第一次使用 XSLT 和 MSXML2。当然它不起作用:-)我有一个我无法解决的错误。 为了修复这个 bug,我试图了解周围的一切:但有件事让我震惊。 void xsltProcessing(IX
我使用 atl 和 CComPtr,像这样: CComPtr xml_doc; HRESULT hr = xml_doc.CoCreateInstance(__uuidof(DOMDocument))
我是一名优秀的程序员,十分优秀!