Parsing a XMLDocument in a DLL - A.V.

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
BarCode99Asked:
Who is Participating?
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.

Wim ten BrinkSelf-employed developerCommented:
XML is case-sensitive. Is it 'ApplicationVersion' or 'applicationversion'?
0
BarCode99Author Commented:
The text is copied straight from the XML file ("ApplicationVersion")...
0
BarCode99Author Commented:
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
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

BarCode99Author Commented:
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
bpanaCommented:
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
BarCode99Author Commented:
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
Wim ten BrinkSelf-employed developerCommented:
PAQ and refund acceptable by me.
0
bpanaCommented:
It's ok for me too.
0
moduloCommented:
Closed, 125 points refunded.


Thanks Workshop_Alex and bpana !

modulo
Community Support Moderator
Experts Exchange
0

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

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.