Solved

Creating XMLDOMDocument in Delphi

Posted on 2003-11-05
38
3,799 Views
Last Modified: 2008-01-09
I'm trying to create a XMLDOMDocument in Delphi 6.0. I have the following code for that:

var
   XMLDoc : IXMLDOMDocument;
begin
   XMLDoc := CreateOleObject ('Microsoft.XMLDOM') as IXMLDomDocument;
   XMLDoc.async := False;
   //Statement for loading a file to that object...
end;

But I have errors:
1)"Undeclared identifier: 'IXMLDOMDocument'"
2)"Undeclared identifier: 'CreateOleObject'"
3)"Operator not applicable to this operand type" (This is for CreateOleObject statement)
4)"Missing operator or semicolon" (This is for XMLDoc.async statement)

What should I do to get rid of these errors? I need your answer as soon as possible. Thank you for your help...
0
Comment
Question by:Ladybuggy
  • 19
  • 16
38 Comments
 
LVL 12

Accepted Solution

by:
andrewjb earned 130 total points
ID: 9685900
You need to Component/Import ActiveX Control then look for the microsoft xml parser, and do import.
This gives you an MSXML2_TLB unit

'uses' this in your source file.

then the way I've used it before is something like

uses
  MSXML2_TLB;

var
  Doc : IXMLDomDocument;

begin

  Doc := CoDOMDocument.Create;

0
 

Author Comment

by:Ladybuggy
ID: 9685960
In Import ActiveX Control list I don't have the Microsoft XML Parser. How can I have it in the list?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686002
'Add', then browse to <Windows>/System32/ and look for, I think, msxml2.dll
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:Ladybuggy
ID: 9686071
When I brosed System32/ directory I found 'msxml3.dll' and clicked to open. But nothing added to the list. What should I do now?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686123
Err.. sorry. Have you got Project/Import Type Library.... That'd work better!

Ooops.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686126
(You'll have to 'Add' again if it's not there already)
0
 

Author Comment

by:Ladybuggy
ID: 9686140
I have tried several times but the result is the same... :(
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686161
What, on the import type library one?
0
 

Author Comment

by:Ladybuggy
ID: 9686239
No, it was for Import ActiveX Control. Now I imported type library. I added 'uses MSXML2_TLB' and the program runs correctly till a statement that I tried to assign a XMLDOMDocument to a variable defined as IXMLDomDocument. It gives the error: 'Incompatible types: 'IDispatch' and 'IXMLDOMDocument''... Now what should I do?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686256
Can you post a code snippet?
0
 

Author Comment

by:Ladybuggy
ID: 9686285
Here the function 'TaminoNonXml1......' returns XMLDOMDocument...

var
   XMLDoc : IXMLDOMDocument;
begin
   XMLDoc := CoDomDocument.Create;
   XMLDoc.async := False;
   XMLDoc := TaminoNonXml1.SetNonXmlWithFilename(Null, 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc', 'application/msword');
end;
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686306
OK -that doesn't make sense. You don't need to create the CoDomDocument if the Temino... function is doing it for you...

You'll have to give a bit of the Tamino...SetNonXml..() function code, too.
0
 

Author Comment

by:Ladybuggy
ID: 9686357
I just have the following information about this function, because that is an '.ocx' an I don't know inside of it:

SetNonXmlWithFilename
LPDISPATCH SetNonXmlWithFilename(BSTR lpszRelURL, BSTR lpszInputFile, BSTR lpszContentType)

Puts a document or file into the Tamino database.
Parameters:
lpszRelURL - NULL, or the relative URL added to the database URL if it does not begin with "http://
lpszFile - the name of the document or file to be read
lpszContentType - the value of the HTTP header "Content-Type" (e.g., "application/msword")
Return Type:
IXMLDOMDocument: DOM tree corresponding to response [if NULL use GetErrorStatus]
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686388
OK, so it returns you an IDispatch pointer, which is really pointing to an IXMLDomDocument.

You need to QueryInterface on the returned pointer. Hang on... i'll have to see how to do that in Delphi!

0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686438
Hmmmm. Haven't got it installed here.

Right - try the following:

var
  Temp : IDispatch;
  res : integer;
begin
...

Temp = TaminoNonXml1.SetNonXmlWithFilename(....) etc.

then

res := Temp.QueryInterface( IXMLDOMDocument , XMLDoc);

and res should be zero, and your XMLdoc should be set.

But I can't try it!

0
 

Author Comment

by:Ladybuggy
ID: 9686499
I wrote the code and put a breakpoint to the statement 'Temp := Tamino...'. It gives the following error to that statement at runtime: "Project *.exe raised exception class EVariantError with message 'Invalid variant type conversion'. Process stopped. Use Step or Run to continue."
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686600
OK - try just calling the function on it's own (don't assign the result to anything). Does that work? Which proves whether it's the function call that fails, or the assignment to Temp
0
 

Author Comment

by:Ladybuggy
ID: 9686630
It gives the same error when I just called the function without assigning the result to something...
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686676
Try with a normal filename for a moment i.e. one without weird characters in it...

Then try passing '' as the first parameter instead of NULL (not what you want in the end, but we're trying to find where the problem lies)
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9686691
Then try

var x: widestring

x := '......your filename'

and pass x as the parameter, instead of the string literal
(and do the same for the other 2 parameters)
0
 

Author Comment

by:Ladybuggy
ID: 9692803
Good morning andrewjb... (It's morning here) I applied all you said... Now the code is like the following:

var
   XMLDoc : IXMLDOMDocument;
   Temp   : IDispatch;
   res    : Integer;
   relURL, FileName, ContentType : Widestring;
begin
   relURL      := 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc';
   FileName    := 'D:\Pelin\Tez\&#304;çerik Geli&#351;tirme Arac&#305;\Gecici_Dosya.doc';
   ContentType := 'application/msword';

   XMLDoc := CoDomDocument.Create;
   XMLDoc.async := False;
   Temp := TaminoNonXml1.SetNonXmlWithFilename(relURL, FileName, ContentType);
   res  := Temp.QueryInterface( IXMLDOMDocument , XMLDoc);
end;

1) It gives no error for "Temp := TaminoNonXml1..." statement, but after the execution of that statement, the Temp variable stays the same (Nil). Is this normal?
2) Now there is an error for the "res := Temp...". It says: "EAccessViolation with message 'Access violation at address XXX in module *.exe'" and the res variable is 0 before and after the execution of the statement. What should I do now?

Thanks for help...
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9693067
No Temp shouldn't be nil. That means the SetNonXML.... didn't work.
OK. So we've sorted out that the original variant problem was with the strings, when you called the function.
Looking at your documentation, I don't think that relURL should be like that... you probably _do_ want to pass nil across.

So, try it with NULL or nil. We need 'Temp' to have a value when the function returns.

0
 

Author Comment

by:Ladybuggy
ID: 9693126
I tried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename(Null, FileName, ContentType);" and it gives the error: "EVariantError with message 'Invalid variant type conversion'".

Itried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename('', FileName, ContentType);" and it returns the Temp variable nil. Gives address violation error to the next line.

I tried it like: "Temp := TaminoNonXml1.SetNonXmlWithFilename(nil, FileName, ContentType);" and it gives the error "Incompatible types: 'WideString' and 'Pointer'.
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9693128
For pity's sake!

hang on a mo....
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9693137
You must somewhere have a delphi prototype for the SetNonXMLWithFilename function. Could you post it, please.
0
 

Author Comment

by:Ladybuggy
ID: 9693155
Can I look inside the '*.ocx' in Delphi?
0
 

Author Comment

by:Ladybuggy
ID: 9693298
Where should I look for the prototype?
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9693497
You must have imported the ocx to get a .pas file. Look in your 'uses' clause - is there something like TaminoNonXml or something? Otherwise, search all .aps files for 'SetNonXMLWithFilename' and you should find it!
0
 

Author Comment

by:Ladybuggy
ID: 9693556
I can just find these lines in TAMINONONXMLLib_TLB.pas:

function  SetNonXmlWithFilename(const url: WideString; const inputFile: WideString; const contenttype: WideString): IDispatch; dispid 6;

function  TTaminoNonXml.SetNonXmlWithFilename(const url: WideString; const inputFile: WideString; const contenttype: WideString): IDispatch;
begin
  DefaultInterface.SetNonXmlWithFilename(url, inputFile, contenttype);
end;    
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9693707
OK - that's what I needed. Not sure how Delphi deals with these WideStrings. COM calls only deal in BSTR (which are similar, but not the same...)

I'll have a look at this, but just for the moment, try setting
relURL := 'http://' and trying the last one again.

0
 

Author Comment

by:Ladybuggy
ID: 9693742
The same: Temp is returned nil and in the next statement "Address Violation" error...
0
 

Author Comment

by:Ladybuggy
ID: 9699581
Did you find something? I'm still at the same point... :(
0
 

Expert Comment

by:HurremSultan
ID: 9875416
I also have something like that and it gives the same error... Aren't you going to help on this problem... I need the solution as soon as possible...
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9881737
Right. Sorry - forgot about this one.

To pass a NULL across, you just use an empty string i.e. ''
 So, your call should look something like

Temp := TaminoNonXml1.SetNonXmlWithFilename('', FileName, ContentType);"

or maybe even better:

s : WideString;
s := '';
Temp := TaminoNonXml1.SetNonXmlWithFilename(s, FileName, ContentType);


If that still returns 'nil', then it's a problem with the SetNonXMLWithFilename() function, which doesn't like the values you are sending it for some reason. I don't know what this TaminoNonXML COM object does, so can't help any more than that....

0
 

Author Comment

by:Ladybuggy
ID: 9881797
Both still returns 'nil'. But I recognized that although it returns nil, it writes the file to the database (this function writes a nonXML file to a XML database). Do you have any comment on that?

Thanks for assistance...
0
 
LVL 12

Expert Comment

by:andrewjb
ID: 9881962
Right then. So call GetErrorStatus on the TaminoNonXML and see what that gives you. I presume you've some documentation for that function somewhere?
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question