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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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.
Exploring SQL Server 2016: Fundamentals

Learn the fundamentals of Microsoft SQL Server, a relational database management system that stores and retrieves data when requested by other software applications.

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?
Eddie ShipmanAll-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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AlfredMelbourneAuthor 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.
AlfredMelbourneAuthor 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.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.