Solved

Creating XMLDOMDocument in Delphi

Posted on 2003-11-05
38
3,714 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
Comment Utility
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
Comment Utility
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
Comment Utility
'Add', then browse to <Windows>/System32/ and look for, I think, msxml2.dll
0
 

Author Comment

by:Ladybuggy
Comment Utility
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
Comment Utility
Err.. sorry. Have you got Project/Import Type Library.... That'd work better!

Ooops.
0
 
LVL 12

Expert Comment

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

Author Comment

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

Expert Comment

by:andrewjb
Comment Utility
What, on the import type library one?
0
 

Author Comment

by:Ladybuggy
Comment Utility
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
Comment Utility
Can you post a code snippet?
0
 

Author Comment

by:Ladybuggy
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
It gives the same error when I just called the function without assigning the result to something...
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
For pity's sake!

hang on a mo....
0
 
LVL 12

Expert Comment

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

Author Comment

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

Author Comment

by:Ladybuggy
Comment Utility
Where should I look for the prototype?
0
 
LVL 12

Expert Comment

by:andrewjb
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
The same: Temp is returned nil and in the next statement "Address Violation" error...
0
 

Author Comment

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

Expert Comment

by:HurremSultan
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now