Solved

TXMLDocument works on TForm, but not on TWebModule

Posted on 2012-04-09
12
557 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 89
code issue 8 128
Delphi: Connect to running MS Outlook 4 80
Twebbrowser add css to the header 3 24
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

785 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