Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: ProhibitDTD in Delphi 2010


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 20 - Last Post: Jun 23, 2014 9:26 PM Last Post By: Katharina Dorn Threads: [ Previous | Next ]
Jan Mitrovics

Posts: 1
Registered: 6/19/00
ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Aug 28, 2009 10:04 AM
I am running into a problem wirth Delphi 2010 and TXMLDocument.

I am using MSXML as DOM Vendor and whenever I try to load any XML file that contains a reference to a DTD I get a 'DTD is prohibited' error.

Seems that for security reasons Microsoft has changed the default for the ProhibitDTD property in MSXML 6.0 to true (it was false before).

Is there a way to set ProhibitDTD to false?
wang yang

Posts: 2
Registered: 11/3/00
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2009 10:23 PM   in response to: Jan Mitrovics in response to: Jan Mitrovics
Jan Mitrovics wrote:
I am running into a problem wirth Delphi 2010 and TXMLDocument.

I am using MSXML as DOM Vendor and whenever I try to load any XML file that contains a reference to a DTD I get a 'DTD is prohibited' error.

Seems that for security reasons Microsoft has changed the default for the ProhibitDTD property in MSXML 6.0 to true (it was false before).

Is there a way to set ProhibitDTD to false?

I have the sme issue. Who can help us... thanks first.
I put a TXmlDocument component on a form and set it's filename to an invalid(DTD is missing) xml file name. And set Active to "True", then the error occured
The resolved external is false. How can i set the property "ProhibitDTD" ?

Jonathan Weekes

Posts: 2
Registered: 6/15/06
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2010 9:39 AM   in response to: wang yang in response to: wang yang
"DUMBY", doh!
wang yang

Posts: 2
Registered: 11/3/00
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 15, 2009 10:32 PM   in response to: Jan Mitrovics in response to: Jan Mitrovics
Jan Mitrovics wrote:
I am running into a problem wirth Delphi 2010 and TXMLDocument.

I am using MSXML as DOM Vendor and whenever I try to load any XML file that contains a reference to a DTD I get a 'DTD is prohibited' error.

Seems that for security reasons Microsoft has changed the default for the ProhibitDTD property in MSXML 6.0 to true (it was false before).

Is there a way to set ProhibitDTD to false?

I found a temp solution. :(

I modified msxmldom.pas and redeclared the TMSDOMDocument.GetMSDocument method.
Make GetMSDocument return IXMLDOMDocument2. And add following codes after "Result := MSNOde as IXMLDOMDocument2;"
Result.SetProperty("ProhibitDTD", False);

Copy the file to my project, compile and run. Now it works well.
But i don't know the risk. Can someone evaluate it? Thanks!

Jonathan Weekes

Posts: 1
Registered: 6/7/06
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2010 9:17 AM   in response to: wang yang in response to: wang yang
Just wanted to say, "THANK YOU, MR. YANG!!!"

I was pulling hens teeth trying to figure out how to implement XSL transformation via TXMLDocument.TransformNode and the ProhibitDTD restriction just about pushed me over the edge . . . just when I thought I had it all figured out, I hit this wall.

Thank goodness I stumbled on this post. It would be very nice to get a follow up from the Delphi guys to hear if there are future plans to officially resolve this significant limitation.

For what it's worth (in case it will help someone else), following is the code I came up with to a) Transform XML > XSL to HTML and b) display the HTML in a TWebBrowser control via a stream--stream was necessary since HTML was apparently too complex to use TWebBrowser.Navigate("about:" + [HTML string]):

  function TfrmMain.VCL_XML_Transform(p_sXML: string; p_sXSL: string): WideString;
var
Component: TComponent;
XML: TXMLDocument;
XSL: TXMLDocument;
begin
// NOTE: if XML or XSL contain DTD's/<!DOCTYPE ...> declarations, it is necessary to modify the return type of msxmldom.pas > TMSDOMDocument.GetMSDocument
// from IXMLDOMDocument to IXMLDOMDocument2 and to set the [IXMLDOMDocument2] "ProhibitDTD" property to FALSE, as follows:
//
// // Modification of msxmldom.pas (saved locally in DATA_OBJECTS_R)
//
// // jweekes 06/2010.001 function TMSDOMDocument.GetMSDocument: IXMLDOMDocument; // jweekes 06/2010.001 (removed)
// function TMSDOMDocument.GetMSDocument: IXMLDOMDocument2; // jweekes 06/2010.001 (replacement)
// begin
// // jweekes 06/2010.001 Result := MSNode as IXMLDOMDocument; // jweekes 06/2010.001 (removed)
// Result := MSNode as IXMLDOMDocument2; // jweekes 06/2010.001 (replacement)
//
// // Default ProhibitDTD to FALSE to allow <!DOCTYPE ...> declarations // jweekes 06/2010.002 (add)
// Result.setProperty('ProhibitDTD', false); // jweekes 06/2010.002 (add)
// end;

// Default Result
Result := '';

// Create DUMBY TComponent to act as OWNER of TXMLDocument objects--this is necessary in order for processing below to work
Component := TComponent.Create(nil);
// Create XML and XSL TXMLDocument objects
XML := TXMLDocument.Create(Component);
XSL := TXMLDocument.Create(Component);
try
// Load XML TXMLDocument object from XML parameter
XML.DOMVendor := GetDOMVendor('MSXML');
XML.LoadFromXML(p_sXML);

// Load XSL TXMLDocument object from XSL parameter
XML.DOMVendor := GetDOMVendor('MSXML');
XSL.LoadFromXML(p_sXSL);

// TRANSFORM into HTML from XML > XSL, setting RESULT to transformed HTML
XML.DocumentElement.TransformNode(XSL.DocumentElement, Result);
finally
// DE-REFERENCE/FREE objects
// NOTE: Only setting TXMLDocuments to NIL--.Free results in Access Violation runtime error. Internet searches indicate that .Free is not necessary;
// apparently, TXMLDocument (IXMLDocument) is an INTERFACE (whatever that really means) and, thus, will be freed automatically when there are no more
// references to it. FastMM does not report any memory leaks with this processing.
XSL := nil;
XML := nil;
Component.Free();
end;
end;

procedure TfrmMain.VCL_TWebBrowser_LoadFromStream(p_sHTML: string; p_WebBrowser: TWebBrowser);
var
HTMLStream: TMemoryStream;
HTMLStreamAdapter: TStreamAdapter;
HTMLStringList: TStringList;
begin
// Load TWebBrowser with BLANK DOCUMENT
// NOTE: This is necessary in order for the "LoadFromStream" processing below to work
p_WebBrowser.Navigate('about:blank');

try
// Create processing objects
// - TStringList to STREAM HTML text for TWebBrowser load
HTMLStringList := TStringList.Create();
// - TMemoryStream for streaming TStringList
HTMLStream := TMemoryStream.Create();

// Create STREAM of HTML text
// - Set HTML TStringList from HTML string parameter
HTMLStringList.Text := p_sHTML;
// - Save HTML from TStringList to STREAM
HTMLStringList.SaveToStream(HTMLStream);
// - Reset HTML Memory Stream to the front of the stream
HTMLStream.Position := 0;

// Create TStreamAdapter object from HTML Stream
HTMLStreamAdapter := TStreamAdapter.Create(HTMLStream, soReference);

// Load TWebBrowser from HTML Stream
(p_WebBrowser.Document as IPersistStreamInit).Load(HTMLStreamAdapter);
finally
// DE-REFERENCE TStreamAdapter object
// NOTE: .Free will create access violation error; thus, just setting to nil to DEREFERENCE. FastMM does not report any memory leaks with this processing.
// HTMLStreamAdapter.Free(); <-- Access Violation error
if Assigned(HTMLStreamAdapter) then HTMLStreamAdapter := nil;

// FREE objects
// - HTML TMemoryStream
if Assigned(HTMLStream) then HTMLStream.Free();
// - HTML TStringList
if Assigned(HTMLStringList) then HTMLStringList.Free();
end;
end;

References:
- Introduction to XSLT (with Delphi) (use of TXMLDocument.DocumentElement.TransformNode): http://www.prototypical.co.uk/pdf/intxslt.pdf
- Load TWebBrowser's document content from stream or string: http://www.delphi3000.com/articles/article_1934.asp?SK=
- TRichEdit/TStringList to Stream: http://bcbjournal.org/articles/vol2/9811/Transferring_TRichEdit_text.htm
- Modify MSXMLDOM.pas to all setting MSDOMDocument.ProhibitDTD to FALSE: https://forums.embarcadero.com/thread.jspa?threadID=23841

(kind of sad that one has to scour the internet to figure out how to do these things vs. looking in the help file for examples--not to mention having to hack, no offense, Mr. Yang, core language code. Delphi FTW!)

wang yang wrote:
Jan Mitrovics wrote:
I am running into a problem wirth Delphi 2010 and TXMLDocument.

I am using MSXML as DOM Vendor and whenever I try to load any XML file that contains a reference to a DTD I get a 'DTD is prohibited' error.

Seems that for security reasons Microsoft has changed the default for the ProhibitDTD property in MSXML 6.0 to true (it was false before).

Is there a way to set ProhibitDTD to false?

I found a temp solution. :(

I modified msxmldom.pas and redeclared the TMSDOMDocument.GetMSDocument method.
Make GetMSDocument return IXMLDOMDocument2. And add following codes after "Result := MSNOde as IXMLDOMDocument2;"
Result.SetProperty("ProhibitDTD", False);

Copy the file to my project, compile and run. Now it works well.
But i don't know the risk. Can someone evaluate it? Thanks!

Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 16, 2010 12:04 PM   in response to: wang yang in response to: wang yang
<wang yang> wrote in message news:162737 at forums dot embarcadero dot com...

I found a temp solution. :(

That is the only way to do it. This topic has been discussed before:

https://forums.embarcadero.com/thread.jspa?threadID=28989&tstart=0

--
Remy Lebeau (TeamB)
Jens Doll

Posts: 1
Registered: 9/19/03
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 18, 2011 10:42 AM   in response to: wang yang in response to: wang yang
wang yang wrote:
Jan Mitrovics wrote:
I am running into a problem wirth Delphi 2010 and TXMLDocument.

I am using MSXML as DOM Vendor and whenever I try to load any XML file that contains a reference to a DTD I get a 'DTD is prohibited' error.

Seems that for security reasons Microsoft has changed the default for the ProhibitDTD property in MSXML 6.0 to true (it was false before).

Is there a way to set ProhibitDTD to false?

I found a temp solution. :(

I modified msxmldom.pas and redeclared the TMSDOMDocument.GetMSDocument method.
Make GetMSDocument return IXMLDOMDocument2. And add following codes after "Result := MSNOde as IXMLDOMDocument2;"
Result.SetProperty("ProhibitDTD", False);

Copy the file to my project, compile and run. Now it works well.
But i don't know the risk. Can someone evaluate it? Thanks!


****************** :-) :-) Thats a real goodie :-) :-) ********************************

Wang,
Thank you!
I applied your solution and it works fine in RAD Studio 2010!!
Jens
Jonathan Weekes

Posts: 2
Registered: 6/15/06
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 21, 2010 3:19 PM   in response to: Jan Mitrovics in response to: Jan Mitrovics
I'm back . . . with my tail between my legs, after my less than friendly "Delphi FTW" comment . . .

The modification of msxmldom.pas file method (changing the return type of GetMSDocument to IXMLDOMDocument2 and setting 'ProhibitDTD' to false) is working great for me . . . in a standard, stand-alone .Exe.

Unfortunately, I am trying to incorporate this functionality into a package. On compiling, I am (not surprisingly, I guess) receiving the following error: "[DCC Error] DATA_OBJECTS_R.dpk(56): E2200 Package 'xmlrtl' already contains unit 'msxmldom'".

  requires
    rtl,
    vcl,
    dbrtl,
    dsnap,
    madBasic_,
    madDisAsm_,
    madExcept_,
    adortl,
    bdertl,
    vclie,
    xmlrtl;   // <- msxmldom.pas already included in this.
 
  contains
    . . . 
    msxmldom in 'msxmldom.pas';  // <- Inclusion of LOCAL modification of msxmldom.pas; generates error since msxmldom.pas already included in xmlrtl above.


In all my searching, I have found no way to "re-include" a file in a package that is already included in another "requires" object.

Any suggestions as to how I can get around this? Is my only option to re-compile xmlrtl with the modified msxmldom.pas and reference the modified xmlrtl in my package? Is that even an option? Where do I find the "Package" for xmlrtl?

As always, any help or direction appreciated.

Humbly (to the best that I'm able),

Jonathan Weekes
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 21, 2010 4:55 PM   in response to: Jonathan Weekes in response to: Jonathan Weekes
<Jonathan Weekes> wrote in message news:253718 at forums dot embarcadero dot com...

The modification of msxmldom.pas file method (changing
the return type of GetMSDocument to IXMLDOMDocument2
and setting 'ProhibitDTD' to false) is working great for me . . .
in a standard, stand-alone .Exe.

You did not need to change the return type. Leave GetMSDocument() as
returning an IXMLDOMDocument pointer, and set the ProhibitDTD property
directly in GetMSDocument() itself instead, ie:

function TMSDOMDocument.GetMSDocument: IXMLDOMDocument;
begin
  Result := MSNode as IXMLDOMDocument;
  if Result is IXMLDOMDocument2 then
      (Result as IXMLDOMDocument2).ProhibitDTD := False;
end;


That way, you are not making any changes to the public interfaces of the
unit.

Unfortunately, I am trying to incorporate this functionality
into a package.

Unfortunately, compiling modifications to RTL/VCL units does not work when
runtime packages are in use.

--
Remy Lebeau (TeamB)
Eric Kramer

Posts: 1
Registered: 6/9/08
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 25, 2011 12:39 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy,

I was able to get the solution of changing the return type to IXMLDOMDocument2 to work in C++ Builder 2010, but when I try to use your suggestion of doing a check for IXMLDOMDocument2 and conditionally setting the ProhibitDTD flag, I get the following DCC errors:

[DCC Error] msxmldom.pas(1132): E2015 Operator not applicable to this operand type
[DCC Error] msxmldom.pas(1133): E2003 Undeclared identifier: 'ProhibitDTD'
[DCC Fatal Error] xmldom.pas(606): F2063 Could not compile used unit 'msxmldom'

Any suggestions on using your proper work around that does not change the interface, but will compile for C++ Builder?

Thanks,
Eric

Remy Lebeau (TeamB) wrote:
<Jonathan Weekes> wrote in message news:253718 at forums dot embarcadero dot com...

The modification of msxmldom.pas file method (changing
the return type of GetMSDocument to IXMLDOMDocument2
and setting 'ProhibitDTD' to false) is working great for me . . .
in a standard, stand-alone .Exe.

You did not need to change the return type. Leave GetMSDocument() as
returning an IXMLDOMDocument pointer, and set the ProhibitDTD property
directly in GetMSDocument() itself instead, ie:

function TMSDOMDocument.GetMSDocument: IXMLDOMDocument;
begin
  Result := MSNode as IXMLDOMDocument;
  if Result is IXMLDOMDocument2 then
      (Result as IXMLDOMDocument2).ProhibitDTD := False;
end;


That way, you are not making any changes to the public interfaces of the
unit.

Unfortunately, I am trying to incorporate this functionality
into a package.

Unfortunately, compiling modifications to RTL/VCL units does not work when
runtime packages are in use.

--
Remy Lebeau (TeamB)
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 25, 2011 4:09 PM   in response to: Eric Kramer in response to: Eric Kramer
<Eric Kramer> wrote in message news:353897 at forums dot embarcadero dot com...

I was able to get the solution of changing the return type to
IXMLDOMDocument2 to work in C++ Builder 2010, but when I try to use your
suggestion of doing a check for IXMLDOMDocument2 and conditionally setting
the ProhibitDTD flag, I get the following DCC errors:

[DCC Error] msxmldom.pas(1132): E2015 Operator not applicable to this
operand type
[DCC Error] msxmldom.pas(1133): E2003 Undeclared identifier: 'ProhibitDTD'
[DCC Fatal Error] xmldom.pas(606): F2063 Could not compile used unit
'msxmldom'

Any suggestions on using your proper work around that does not change the
interface, but will compile for C++ Builder?

IXMLDOMDocument2 does not have an actual ProhibitDTD property defined in its
interface. You have to use the setProperty() method instead, eg:

function TMSDOMDocument.GetMSDocument: IXMLDOMDocument;
var
  Doc2: IXMLDOMDocument2;
begin
  Result := MSNode as IXMLDOMDocument;
  if Supports(Result, IXMLDOMDocument2, Doc2) then
      Doc2.setProperty('ProhibitDTD', False);
end;


--
Remy Lebeau (TeamB)
Marc Durdin

Posts: 1
Registered: 10/9/08
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 1, 2011 6:35 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Remy Lebeau (TeamB) wrote:

IXMLDOMDocument2 does not have an actual ProhibitDTD property defined in its
interface. You have to use the setProperty() method instead, eg:

function TMSDOMDocument.GetMSDocument: IXMLDOMDocument;
var
  Doc2: IXMLDOMDocument2;
begin
  Result := MSNode as IXMLDOMDocument;
  if Supports(Result, IXMLDOMDocument2, Doc2) then
      Doc2.setProperty('ProhibitDTD', False);
end;

As an alternative to modifying the VCL source (I note ProhibitDTD property workaround is in XE2, but same problem arises for other properties such as AllowDocumentFunction), you could replace the default CreateDOMDocument implementation. This worked for us: http://marc.durdin.net/2011/11/workaround-for-allowdocumentfunction.html
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Nov 2, 2011 4:24 PM   in response to: Marc Durdin in response to: Marc Durdin
<Marc Durdin> wrote in message news:416039 at forums dot embarcadero dot com...

As an alternative to modifying the VCL source (I note ProhibitDTD
property workaround is in XE2, but same problem arises for
other properties such as AllowDocumentFunction), you could
replace the default CreateDOMDocument implementation.

Yes, that will work, though I would opt for something more like this:

function TryObjectCreate(const GuidList: array of TGuid): IXMLDOMDocument;
var
  I: Integer;
begin
  Result := nil;
  for I := Low(GuidList) to High(GuidList) do begin
    if CoCreateInstance(GuidList[I], nil, CLSCTX_INPROC_SERVER or 
CLSCTX_LOCAL_SERVER, IXMLDOMDocument, Result) = S_OK then Exit;
  end;
  raise DOMException.Create(SMSDOMNotInstalled);
end;
 
function CreateDOMDocument: IXMLDOMDocument;
var
  Doc2: IXMLDOMDocument2;
begin
  Result := TryObjectCreate([CLASS_DOMDocument60, CLASS_DOMDocument40, 
CLASS_DOMDocument30, CLASS_DOMDocument26, CLASS_DOMDocument]);
  if Supports(Result, IXMLDOMDocument2, Doc2) then
  begin
    Doc2.SetProperty('AllowDocumentFunction', True);
    ...
  end;
end;


--
Remy Lebeau (TeamB)
Jason Sweby

Posts: 46
Registered: 5/20/00
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 25, 2014 1:15 AM   in response to: Jan Mitrovics in response to: Jan Mitrovics
Just as an update, as I came across this in Delphi XE3. I tried the MSXML TransformNode fix suggested above, which came back with warnings that some methods were deprecated. Searching around the source code, I ended up adding this line to my code:

TXMXMLDocumentFactory.AddDOMProperty('AllowDocumentFunction', True);

This worked and the "AllowDocumentFunction constraints violated" error went away.
Katharina Dorn

Posts: 29
Registered: 7/19/14
Re: ProhibitDTD in Delphi 2010  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 19, 2014 2:08 AM   in response to: Jason Sweby in response to: Jason Sweby
Hello!

Iam new.
I use Embarcadero 2010.

I have the Problem with the prohibited DTD. I tried all the references. Nothing helped me. What can i do?
MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False, True); <--does not work, MSXMLDOMDocumentFactory unknown

MSXML6_ProhibitDTD = false; <-- does not work, at the beginning i must declare bool MSXML6_ProhibitDTD. Only with that i can use it.

And i changed msxmldom.pas. Even during the duration of my program.

I'm glad, if i can get help.

Greetings

_______________________________________

Jason Sweby wrote:
Just as an update, as I came across this in Delphi XE3. I tried the MSXML TransformNode fix suggested above, which came back with warnings that some methods were deprecated. Searching around the source code, I ended up adding this line to my code:

TXMXMLDocumentFactory.AddDOMProperty('AllowDocumentFunction', True);

This worked and the "AllowDocumentFunction constraints violated" error went away.

Edited by: Katharina Dorn on Jun 19, 2014 2:13 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 19, 2014 11:29 AM   in response to: Katharina Dorn in response to: Katharina Dorn
Katharina wrote:

MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False, True);
<--does not work, MSXMLDOMDocumentFactory unknown

The MSXMLDOMDocumentFactory variable and the AddDOMProperty() method were
both introduced in Delphi XE3.

MSXML6_ProhibitDTD = false; <-- does not work

The MSXML6_ProhibitDTD variable was introduced in Delphi XE.

And i changed msxmldom.pas. Even during the duration of my program.

You do not need to do that. In Delphi 2010, all you need to do is assign
a handler to the MSXMLDOMDocumentCreate callback, eg:

uses
  ..., msxmldom;
 
function MyMSXMLDOMDocumentCreate: IXMLDOMDocument;
begin
  Result := msxmldom.CreateDOMDocument;
  if Result is IXMLDOMDocument2 then
  begin
    (Result as IXMLDOMDocument2).ProhibitDTD := False;
    // Or: (Result as IXMLDOMDocument2).SetProperty('ProhibitDTD', False);
  end;
end;
 
initialization
  MSXMLDOMDocumentCreate := MyMSXMLDOMDocumentCreate;


--
Remy Lebeau (TeamB)
Katharina Dorn

Posts: 29
Registered: 7/19/14
Re: ProhibitDTD in Delphi 2010 [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 19, 2014 11:39 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hey,

thank you for help.

Can u write the code in C++?

uses
  ..., msxmldom;
 
function MyMSXMLDOMDocumentCreate: IXMLDOMDocument;
begin
  Result := msxmldom.CreateDOMDocument;
  if Result is IXMLDOMDocument2 then
  begin
    (Result as IXMLDOMDocument2).ProhibitDTD := False;
    // Or: (Result as IXMLDOMDocument2).SetProperty('ProhibitDTD', False);
  end;
end;
 
initialization
  MSXMLDOMDocumentCreate := MyMSXMLDOMDocumentCreate;

I'm glad, when you can do that.

Can i insert this function below my main?

Greetings


Remy Lebeau (TeamB) wrote:
Katharina wrote:

MSXMLDOMDocumentFactory.AddDOMProperty('ProhibitDTD', False, True);
<--does not work, MSXMLDOMDocumentFactory unknown

The MSXMLDOMDocumentFactory variable and the AddDOMProperty() method were
both introduced in Delphi XE3.

MSXML6_ProhibitDTD = false; <-- does not work

The MSXML6_ProhibitDTD variable was introduced in Delphi XE.

And i changed msxmldom.pas. Even during the duration of my program.

You do not need to do that. In Delphi 2010, all you need to do is assign
a handler to the MSXMLDOMDocumentCreate callback, eg:

uses
  ..., msxmldom;
 
function MyMSXMLDOMDocumentCreate: IXMLDOMDocument;
begin
  Result := msxmldom.CreateDOMDocument;
  if Result is IXMLDOMDocument2 then
  begin
    (Result as IXMLDOMDocument2).ProhibitDTD := False;
    // Or: (Result as IXMLDOMDocument2).SetProperty('ProhibitDTD', False);
  end;
end;
 
initialization
  MSXMLDOMDocumentCreate := MyMSXMLDOMDocumentCreate;


--
Remy Lebeau (TeamB)

Edited by: Katharina Dorn on Jun 20, 2014 12:48 AM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 20, 2014 1:46 PM   in response to: Katharina Dorn in response to: Katharina Dorn
Katharina wrote:

Can u write the code in C++?

#include <Msxmldom.hpp>
 
_di_IXMLDOMDocument __fastcall MyMSXMLDOMDocumentCreate(void)
{
    _di_IXMLDOMDocument Result = CreateDOMDocument();
    DelphiInterface<IXMLDOMDocument2> doc2(Result);
    if (doc2)
    {
        VARIANT v;
        v.vt = VT_BOOL;
        v.boolVal = VARIANT_FALSE;
        doc2->setProperty(WideString("ProhibitDTD").c_bstr(), v);
    }
    return Result;
}
 
MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;


--
Remy Lebeau (TeamB)
Katharina Dorn

Posts: 29
Registered: 7/19/14
Re: ProhibitDTD in Delphi 2010 [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 21, 2014 4:16 AM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Thank you for your help!

But if it's implemented i get mistakes:
In this line "MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;" i get the Error:
- "expected typename"
and
- "Konvertierung von '_di_IXMLDOMDocument (_fastcall *)()' nach 'int' nicht möglich"
("conversion from '_di_IXMLDOMDocument (_fastcall *)()' to 'int' impossible").

What's wrong?

_______________________________

Remy Lebeau (TeamB) wrote:
Katharina wrote:

Can u write the code in C++?

#include <Msxmldom.hpp>
 
_di_IXMLDOMDocument __fastcall MyMSXMLDOMDocumentCreate(void)
{
    _di_IXMLDOMDocument Result = CreateDOMDocument();
    DelphiInterface<IXMLDOMDocument2> doc2(Result);
    if (doc2)
    {
        VARIANT v;
        v.vt = VT_BOOL;
        v.boolVal = VARIANT_FALSE;
        doc2->setProperty(WideString("ProhibitDTD").c_bstr(), v);
    }
    return Result;
}
 
MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;


--
Remy Lebeau (TeamB)

Edited by: Katharina Dorn on Jun 22, 2014 6:32 AM

Edited by: Katharina Dorn on Jun 22, 2014 9:26 PM
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: ProhibitDTD in Delphi 2010 [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 23, 2014 10:54 AM   in response to: Katharina Dorn in response to: Katharina Dorn
Katharina wrote:

In this line "MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;"
i get the Error:
- "expected typename"
and
- "Konvertierung von '_di_IXMLDOMDocument (_fastcall *)()' nach 'int'
nicht möglich"
("conversion from '_di_IXMLDOMDocument (_fastcall *)()' to 'int'
impossible").

That is complete BS. MSXMLDOMDocumentCreate is declared in msxmldom.hpp
as a function pointer, not as an 'int':

typedef Msxml::_di_IXMLDOMDocument __fastcall (*TMSXMLDOMDocumentCreateFunc)(void);
extern PACKAGE TMSXMLDOMDocumentCreateFunc MSXMLDOMDocumentCreate;


Try using a '#pragma startup' statement to assign the function pointer at
runtime:

#include <Msxml.hpp>
#include <Msxmldom.hpp>
 
Msxml::_di_IXMLDOMDocument __fastcall MyMSXMLDOMDocumentCreate(void)
{
    Msxml::_di_IXMLDOMDocument Result = Msxmldom::CreateDOMDocument();
    DelphiInterface<Msxml::IXMLDOMDocument2> doc2(Result);
    if (doc2)
    {
        VARIANT v;
        v.vt = VT_BOOL;
        v.boolVal = VARIANT_FALSE;
        doc2->setProperty(WideString("ProhibitDTD").c_bstr(), v);
    }
    return Result;
}
 
void setMyXmlDomDocumentCreate()
{
    Msxmldom::MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;
}
#pragma startup setMyXmlDomDocumentCreate


--
Remy Lebeau (TeamB)
Katharina Dorn

Posts: 29
Registered: 7/19/14
Re: ProhibitDTD in Delphi 2010 [Edit] [Edit] [Edit]  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Jun 23, 2014 9:26 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hello!

Now it works!

Thank you very much!!!!


Remy Lebeau (TeamB) wrote:
Katharina wrote:

In this line "MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;"
i get the Error:
- "expected typename"
and
- "Konvertierung von '_di_IXMLDOMDocument (_fastcall *)()' nach 'int'
nicht möglich"
("conversion from '_di_IXMLDOMDocument (_fastcall *)()' to 'int'
impossible").

That is complete BS. MSXMLDOMDocumentCreate is declared in msxmldom.hpp
as a function pointer, not as an 'int':

typedef Msxml::_di_IXMLDOMDocument __fastcall (*TMSXMLDOMDocumentCreateFunc)(void);
extern PACKAGE TMSXMLDOMDocumentCreateFunc MSXMLDOMDocumentCreate;


Try using a '#pragma startup' statement to assign the function pointer at
runtime:

#include <Msxml.hpp>
#include <Msxmldom.hpp>
 
Msxml::_di_IXMLDOMDocument __fastcall MyMSXMLDOMDocumentCreate(void)
{
    Msxml::_di_IXMLDOMDocument Result = Msxmldom::CreateDOMDocument();
    DelphiInterface<Msxml::IXMLDOMDocument2> doc2(Result);
    if (doc2)
    {
        VARIANT v;
        v.vt = VT_BOOL;
        v.boolVal = VARIANT_FALSE;
        doc2->setProperty(WideString("ProhibitDTD").c_bstr(), v);
    }
    return Result;
}
 
void setMyXmlDomDocumentCreate()
{
    Msxmldom::MSXMLDOMDocumentCreate = &MyMSXMLDOMDocumentCreate;
}
#pragma startup setMyXmlDomDocumentCreate


--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02