Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Parsing a XMLDocument in a DLL - A.V.

Posted on 2004-11-16
10
Medium Priority
?
1,396 Views
Last Modified: 2009-12-30
Hi all,

I have a DLL that downloads a XML document from a website or a file share and puts it into a TMemoryStream. I then create a TXMLDocument and load the XML from the stream. Like this:

    XMLDocument := TXMLDocument.Create(nil);
    try
      XMLDocument.LoadFromStream(streamXMLFile);
      XMLDocument.Active := true;

Next I need to get one value out of the XML file and carry on doing other stuff, but here comes my problem... When I try to access XMLDocument.DocumentElement I get an Access Violation and I can't figure out why. My code continues like this:

      FNewApplicationVersion := XMLDocument.DocumentElement.ChildNodes.FindNode('ApplicationVersion').Text;   <------ Throws exception
    except
      on E: Exception do begin
        ShowMessage('Error: ' + E.Message);
      end;
    end;

The exception I get is "Access Violation at address 00002000. Read of address 00002000"

My variable declarations look like this:
var
  streamXMLFile : TMemoryStream;
  XMLDocument : TXMLDocument;
  FNewApplicationVersion : String;

As I mentioned this is a DLL. The same code works fine in a normal application... Any ideas?
I have done the trick with including ActiveX in my uses clause and calling CoInitialize in the initialization section.

Best regards,
Marius
0
Comment
Question by:BarCode99
  • 4
  • 2
  • 2
  • +1
9 Comments
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12594755
XML is case-sensitive. Is it 'ApplicationVersion' or 'applicationversion'?
0
 

Author Comment

by:BarCode99
ID: 12594832
The text is copied straight from the XML file ("ApplicationVersion")...
0
 

Author Comment

by:BarCode99
ID: 12594904
Alternatively, are there other components I can use to parse the XML and read the value of a specific node easily?

I know about OpenXML. Does anybody have any experience with it?

Marius
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:BarCode99
ID: 12595813
OK I worked it out, but maybe someone can tell me what I did wrong???

If I change the declaration of XMLDocument from TXMLDocument to IXMLDocument (I not T) and remove the FreeAndNil it all works. The Create statement is still TXMLDocument.Create...

What about memory? Since there is no FreeAndNil, am I leaking like a sieve? Any thoughts?

Marius
0
 
LVL 6

Expert Comment

by:bpana
ID: 12595845
no, when you use a local variable as interface type, it is automatically released when you no longer work with (at the end of procedure).
0
 

Author Comment

by:BarCode99
ID: 12596097
OK, so no worries then...

Thanks for you input  guys.

I'm going to ask for my points back as I solved it myself...

Marius
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 12602464
PAQ and refund acceptable by me.
0
 
LVL 6

Expert Comment

by:bpana
ID: 12602581
It's ok for me too.
0
 

Accepted Solution

by:
modulo earned 0 total points
ID: 12602680
Closed, 125 points refunded.


Thanks Workshop_Alex and bpana !

modulo
Community Support Moderator
Experts Exchange
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This is an update to some code that someone else posted on Experts Exchange. It is an alternate approach, I think a little easier to use, & makes sure that things like the Task Bar will update.
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses
Course of the Month11 days, 16 hours left to enroll

564 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