-2

Okay, so I'm now aware of the fact I need to use TXMLDocument to open a .xml in Delphi 7, but I had a few further questions (hopefully answerable ones that haven't already been answered, I didn't see anything that looked overly helpful)

  • If I run tempdoc.LoadFromFile('document.xml'); - just as an example, it throws up an Access Violation, but I'm not sure what I'm doing wrong there. I looked it up, and the violation ends in 00000000, which indicates that it's not able to find the file, which is why I wanted to ask - Do I need to put the entire filepath in the LoadFromFile('')?

  • If so - I tried to use tempdoc.LoadFromFile(tempbuffer+'shared.xml') - where Tempbuffer is the extracted filepath of everything up to that (in this case 'C:\users\...\Appdata\Roaming\Skype\')

  • I assume, like before, I'm using the part in the wrong way, but as I keep having to point out, this is all new to me. What am I doing wrong here? Is it because of the location of the file, or something else?

  • I haven't yet investigated it properly, because I'm still trying to work out how to actually read the .xml file, but I assume there's a way I can extract the child node from this:

 

<?xml version="1.0"?>
<config version="1.0" serial="56" timestamp="1412085296.3">
    <Lib>
    <Access>
        <Cookies>4100</Cookies>
    </Access>
    <Account>
        <Default>[ACCOUNTNAME]</Default>
    </Account>
    </Lib>
</config>

I'm trying to extract the [ACCOUNTNAME] field from the subnode. Hopefully this is clearer than the previous attempt.

Short version: How does LoadFromFile work? Can I extract a field from a node and turn it into a string?

9
  • possible duplicate of Libraries and tutorials for XML in Delphi Have a look at the TXMLDocument components as mentioned in that QA Commented Oct 2, 2014 at 12:08
  • Apologies, I did check that, but I found it difficult to understand how I was meant to get what I wanted out of the answer there, which is why I asked something more specific. Commented Oct 2, 2014 at 12:11
  • You've not really asked something specific. You've asked for a broad tutorial. Anyone answering this is surely going to just duplicate the gazillion pre-existing tutorials. You've not even managed to show the XML and what you've tried. I think you need to try just a little harder. Commented Oct 2, 2014 at 12:23
  • That's not XML. Please use real XML. And format it inside <pre> tags Commented Oct 2, 2014 at 13:10
  • void, fixed. How is not not XML? What makes XML into XML, etc? Commented Oct 2, 2014 at 13:29

1 Answer 1

4

The reason why you are getting the Acces Violation on

tempdoc.LoadFromFile('document.xml');

is most likely the fact that TXMLDocument has not been created yet, such as by

tempdoc := TXMLDocument.Create(Form1);

Or dropping a TXMLDocument component onto the Form at design-time.

Then you can call

tempdoc.LoadFromFile('document.xml');

Or, if you want to load an existing file right away, by

tempdoc := TXMLDocument.Create('document.xml');

But then tempdoc1 **MUST** be declared asIXMLDocumentinstead ofTXMLDocument`.

The only time when you do not need to create TXMLDocument in code is if you have placed it onto the Form from Component Palette, then it gets automatically created with the Form.

BTW when an access violation occurs at address 00000000, it means you are trying to acces a nil pointer, such as an uninitialized object, or an already freed object.

Sign up to request clarification or add additional context in comments.

1 Comment

Small correction: Address 00000000 does not imply "an already freed object". A reference can be set to nil without destroying an object, and conversely Freeing an object does not mean the reference was also set to nil.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.