Solved

TXMLDocument works on TForm, but not on TWebModule

Posted on 2012-04-09
12
554 Views
Last Modified: 2013-01-20
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.
0
Comment
Question by:AlfredMelbourne
12 Comments
 
LVL 26

Expert Comment

by:EddieShipman
ID: 37825902
Try putting it in a DataModule and using the DM in your TWebModule.
0
 

Author Comment

by:AlfredMelbourne
ID: 37825919
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
0
 

Author Comment

by:AlfredMelbourne
ID: 37826226
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.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 37828303
Personally, I never liked using the TXMLDocument wrapper and used the IXMLDOMDocument directly.
uses ... MSXML3_TLB;

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

Open in new window


If you need more help parsing the document, please post it and tell how you want it parsed.
0
 

Author Comment

by:AlfredMelbourne
ID: 37830432
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?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 26

Accepted Solution

by:
EddieShipman earned 500 total points
ID: 37832490
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.
0
 

Assisted Solution

by:AlfredMelbourne
AlfredMelbourne earned 0 total points
ID: 37854221
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:

uses
  ActiveX ....
...

  CoInitialize(nil);
  StringList1 := TStringList.Create;
  try
  XMLDocument1.LoadFromFile('C:\Temp\MyFile.xml');
  Response.Content := DisplayMessage('ok')
  except
    Response.Content := DisplayMessage('not ok')
    end;

Now I understand why the DLL's didn't work while the .EXE did.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 37855830
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.
0
 

Assisted Solution

by:AlfredMelbourne
AlfredMelbourne earned 0 total points
ID: 37858366
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
0
 
LVL 1

Expert Comment

by:vviioo
ID: 37925722
Try calling CoInitialize before using the XMLDoc and COUninitialize when you are finished.
0
 
LVL 37

Expert Comment

by:Geert Gruwez
ID: 38798049
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 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

13 Experts available now in Live!

Get 1:1 Help Now