Link to home
Start Free TrialLog in
Avatar of Ladybuggy
Ladybuggy

asked on

Creating XMLDOMDocument in Delphi

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...
ASKER CERTIFIED SOLUTION
Avatar of andrewjb
andrewjb
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Ladybuggy
Ladybuggy

ASKER

In Import ActiveX Control list I don't have the Microsoft XML Parser. How can I have it in the list?
'Add', then browse to <Windows>/System32/ and look for, I think, msxml2.dll
When I brosed System32/ directory I found 'msxml3.dll' and clicked to open. But nothing added to the list. What should I do now?
Err.. sorry. Have you got Project/Import Type Library.... That'd work better!

Ooops.
(You'll have to 'Add' again if it's not there already)
I have tried several times but the result is the same... :(
What, on the import type library one?
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?
Can you post a code snippet?
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;
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.
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]
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!

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!

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."
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
It gives the same error when I just called the function without assigning the result to something...
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)
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)
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...
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.

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'.
For pity's sake!

hang on a mo....
You must somewhere have a delphi prototype for the SetNonXMLWithFilename function. Could you post it, please.
Can I look inside the '*.ocx' in Delphi?
Where should I look for the prototype?
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!
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;    
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.

The same: Temp is returned nil and in the next statement "Address Violation" error...
Did you find something? I'm still at the same point... :(
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...
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....

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...
Right then. So call GetErrorStatus on the TaminoNonXML and see what that gives you. I presume you've some documentation for that function somewhere?