I have a question regarding of reading xml files in delphi. I have read a few articles about it, but didn't find what I need anywhere, at least not that I'd notice. Meanwhile, I read the arcticle on How to read data from xml file and display it over the text box in delphi language
However, two things:
first, in the first answer that Remy provided, I believe there is slightly mistaken code: Right after the "try", there is Vehicle := XMLDocument.DocumentElement; but I believe it should be XMLDocument1.DocumentElement instead. Am I right?
[sorry, can't post a comment since I don't have enough reputation.]
secondly, I don't quite get how do I change which record to show. In the example above, there were two records of "vehicle" in the xml file, however I only see like it's only called once, so here's my question, how and where do I define which record/node to read?
To be more specific on what I actually need: I'm trying to read off a sms backup file, which is generated as an xml file, and has the structure as below:
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<?xml-stylesheet type="text/xsl" href="sms.xsl"?>
<smses count="3">
<sms protocol="0" address="~number~" date="1385104712000" type="1" subject="null" body="Message 1 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 8:18:32 AM" contact_name="My contact 1" />
<sms protocol="0" address="~number~" date="1385104912000" type="2" subject="null" body="Message 2 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 8:38:32 AM" contact_name="My contact 2" />
<sms protocol="0" address="~number~" date="1385106412000" type="1" subject="null" body="Message 3 text" toa="145" sc_toa="0" service_center="ˇ~servicecenter~" read="1" status="-1" locked="0" date_sent="0" readable_date="Nov 22, 2013 9:18:32 AM" contact_name="My contact 1" />
</smses>
How could I read these correctly? Notice, that there might be repeatable "address" values. I'd like to add every different contact/number/"address" as an Listbox item, so I can select the contact, and later show the conversation via other elements..
I was thinking of reading the whole xml file to an array of record with length set by the first data in xml, , so I can later access this data directly from the program, as well as maybe write it to database, so the one could make/create organized database of all sms backup xml's he/she has...
With the database etc I don't expect any problems, just need to read the file to the memory first of all.
Any help would be appreciated. Thanks! :)