Solved

TXMLDocument works on TForm, but not on TWebModule

Posted on 2012-04-09
12
560 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 118
select query - oracle 16 100
Find and Replace Stream with 0s 8 69
Breakpoint doesn't stop in my variable 3 30
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

830 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