TXMLDocument works on TForm, but not on TWebModule

I used a test program to make TXMLDocument work the way I wanted and to parse successfully a document.

When I tried to reproduce the same on a TWebModule, it compiled OK, but always failed when reference was made to the TXMLDocument. I tried it both as a component and as a class. I was using the same input file in both cases.

XMLDocument1 := TXMLDocument.Create(nil);

There are plenty of examples here and on the internet of similar usage. BTW, I am running Delphi 7 and Wndows XP. Is there something that I need to install, or suchlike.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

Eddie ShipmanConnect With a Mentor All-around developerCommented:
You have to use the off the Project->Import Type Library... menu. Select the version of Microsoft XML that you have installed. There may be many, and if so, select 3.0. The typelib will be placed in the Imports directory.
Eddie ShipmanAll-around developerCommented:
Try putting it in a DataModule and using the DM in your TWebModule.
AlfredMelbourneAuthor Commented:
Thank you Eddie. Perhaps I have not made myself clear. The failure occurs on the statement

XMLDocument1 := TXMLDocument.Create(nil);

when I am tracing it - before the data has even been read!

If I use a component, which has already been created, it fails when I do a LoadFrommStream or LoadFromFile
The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

AlfredMelbourneAuthor Commented:
FWIW, I tried TALXMLDocument and had exactly the same problem. OTOH, when I tried TWPXMLTree, it worked fine. Obviously, I will have to use WPTools now.

However, I would love to get those other XML parsers to work on my website.
Eddie ShipmanAll-around developerCommented:
Personally, I never liked using the TXMLDocument wrapper and used the IXMLDOMDocument directly.
uses ... MSXML3_TLB;

  oXMLDomDocument : IXMLDOMDocument;
  oXMLDomDocument := CreateOleObject('MSXML2.DOMDocument') as IXMLDOMDocument;
  // use the oXMLDomDocument using the OLE calls.
  .. etc...

Open in new window

If you need more help parsing the document, please post it and tell how you want it parsed.
AlfredMelbourneAuthor Commented:
I think we are getting somewhere.

I don't seem to have MSXML_TLB.pas or MSXML3_TLB on my PC. Where do they come from?
AlfredMelbourneConnect With a Mentor Author Commented:
I used AutomatedQA to find out what was going on. I finally got to the root of the problem as I got the message "CoInitialize has not been called". All I needed to do was the following:

  ActiveX ....

  StringList1 := TStringList.Create;
  Response.Content := DisplayMessage('ok')
    Response.Content := DisplayMessage('not ok')

Now I understand why the DLL's didn't work while the .EXE did.
Eddie ShipmanAll-around developerCommented:
It would have been easier to just use the MSXML TypeLib but if you got it working, great.
That is one reason I do not like using TXMLDocument and another is because it is so convoluted. I began working with MXSML back in 1998, before the TXMLDocument wrapper was even written so I know that way much better.
AlfredMelbourneConnect With a Mentor Author Commented:
I ended up using Turbopower's XMLPartner. I had forgotten that I had bought it a decade ago. It is much easier than WP (which is not free).

I installed a newer - free - copy downloaded from http://sourceforge.net/projects/tpxmlpartner

I even had a written manual somewhere - the PDF version comes with the free install. I strongly recommend it.

Thanks for trying to help
Try calling CoInitialize before using the XMLDoc and COUninitialize when you are finished.
Geert GOracle dbaCommented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.