Read data from XML file to record (+mdb database) - android

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! :)

Related

CSV example for translation service in Google Play Console

I built my first mobile game using Unity and localized it for a few known languages using localization tool created by my own. However, I decided to have a bit more languages and wanted to translate app using Google Play Console Translation Service. Unfortunately, I stuck with CSV file.
Does anyone have an example of CSV file that tool is asking for please? Or maybe any other solution?
Upload your strings.xml file to upload your user interface text if you use Android Studio for development. Upload a CSV file if you use any other tool for development. A CSV file must be encoded in UTF-8 format, and have string IDs and text to translate columns without a header row.
The following XML file worked for me. If the XML is invalid, they'll inform you right away when you upload it.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="inventory">
<item>Rewind</item>
<item>Switch</item>
<item>Mirage Filter</item>
<item>Holy Grenade</item>
</string-array>
<string name="app_name">Gravity</string>
<string name="rewind_desc">Got trapped in the space-time continuum? Rewind time back to the beginning and start over</string>
</resources>
FYI: resources/string-resource
I haven't heard back from translators yet, but by trial and error, this file format was at least accepted by the UI:
UTF-8
Comma as separator
No header row
Column1 stringID
Column2 OriginalText
No extra columns*
Fields quoted with double quotes
Like this:
arno#brick ~ $ cat polsk.csv
"Adminlagre","Adminlagre"
"AlleVerktøy","Alle verktøy"
"BortkomneVerktøy","- Bortkomne verktøy -"
"GarantienUtløpDen","Garantien utløp %0"
"ReservasjonerSenere","Reservasjoner senere"
"SkjulteVerktøy","- Skjulte verktøy -"
"ukjentleverandør","(ukjent leverandør)"
*It seems uploading a csv with 3 columns is accepted too (unsure what that results in), but 4 columns didn't work…

Why is Spannable fromHtml giving me wrong incorrect output if the first quote is escaped? It removes the first sentence

Please read the edit update at the bottom.
I am pretty new to Android so please bear with me. I am able to reproduce my issue with a very simple example.
I have the following in my strings.html:
<string name="nice_html">
<![CDATA[
<div><p><strong>Timeline of my other stories separated by company.</strong></p><p>This story about smashing modems from u/devdevo1919 reminded of this little gem when I was a customer service representative at $SecurityCompany. Now before you say \u201cbut customer service isn\u2019t IT\u201d, let me explain the position. They <em>called</em> us CSRs, but what we really did was mostly technical support for the residential and small business security systems as well as some customer service functions. We had a separate team for the large businesses.</p></div>
]]>
</string>
My mainactivity.xml looks like:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.pranapps.htmltest.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:id="#+id/mylabel"
android:layout_marginTop="25dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
/>
</android.support.constraint.ConstraintLayout>
And the code for activity looks like:
TextView mylabel = (TextView) findViewById(R.id.mylabel);
String htmlstring = getString(R.string.nice_html);
Spannable spannable = (Spannable) Html.fromHtml(htmlstring);
System.out.println("htmlstring: "+htmlstring);
System.out.println("spannable: "+spannable);
mylabel.setText(spannable);
This is giving me the wrong output. Notice how the entire first line of the string is missing in the output and the entire string shows as bold.
The system.out shows that the Spannable is the one causing the issue and it's trimming the entire first line for some reason. Can someone help me why it's doing that?
01-06 15:47:12.470 14719-14719/com.XXXXXX.htmltest I/System.out: htmlstring: <div><p><strong>This story about smashing modems from u/devdevo1919 reminded of this little gem when I was a customer service representative at $SecurityCompany. Now before you say “but customer service isn’t IT”, let me explain the position. They <em>called</em> us CSRs, but what we really did was mostly technical support for the residential and small business security systems as well as some customer service functions. We had a separate team for the large businesses.</p></div>
01-06 15:47:12.470 14719-14719/com.XXXXXX.htmltest I/System.out: spannable: This story about smashing modems from u/devdevo1919 reminded of this little gem when I was a customer service representative at $SecurityCompany. Now before you say “but customer service isn’t IT”, let me explain the position. They called us CSRs, but what we really did was mostly technical support for the residential and small business security systems as well as some customer service functions. We had a separate team for the large businesses.
EDIT: I figured it out but I am curious whether this is a bug. If I remove just the very first \ after href= tag, then it starts to work properly. Is this a bug?
Your HTML is in a CDATA block. AFAIK, you do not need to escape quotation marks there. But, if you do, you need to do so consistently, apparently.
Your second <a> is:
<a href=\"https://redd.it/7jmvxo\">
Note that you have both quotation marks escaped with backslashes.
Your first <a> is:
<a href=\"https://www.reddit.com/r/nosleep/comments/3ijnt6/im_a_search_and_rescue_officer_for_the_us_forest/">
Note that you have escaped the opening quotation mark, but not the closing quotation mark.
Your repaired <a>, based on your comment, is:
<a href="https://www.reddit.com/r/nosleep/comments/3ijnt6/im_a_search_and_rescue_officer_for_the_us_forest/">
If that works, then you do not need to escape quotation marks here, as those are not escaped.
So, I would remove the escape backslashes, to simplify your life.

How to create a string-array in xml format easily?

Say I have a long list like the following:
العربية
مصرى
Asturianu
Azərbaycanca
Žemaitėška
......
How can I convert it to a string-array in xml format?
<item>العربية</item>
<item>مصرى</item>
<item>Asturianu</item>
I actually could not find anything with online search relating xml formats. but I finally came up with this solution.
I copy the list to excel and arrange the in 3 cells and copy-paste to xml. Then and cut paste again all to a new single cell in excel. Replace all " "(single space without "" created for no reason) with ""(just blank without "")
It works, I hope I have not taken the time of too many people

Fetch data from XML file located in sdcard (Android)

This is my first post here :-). I am developing an application for android in eclipse.
My question is I have put an XML file in sdcard with some elements like id,First name and lastname.
Form my UI i have one textbox and button. User will enter ID in the textbox and on click event of button I should fetch the data based on that ID. and display in TextView.
Any help please??
Thanks in advance. :-)
Here is a sample of XML file which is given to me,
<tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>1</ID>
<LastName>Family 1 (1-42-167)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>2</ID>
<LastName>Family 2 (1-4-16)</LastName>
<OtherNames>FamMem1</OtherNames>
<DOB>01-01-85</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
- <tblInsurees xmlns="urn:schemas-microsoft-com:sql:SqlRowSet1">
<ID>3</ID>
<LastName>Family 3 (1-4-16)</LastName>
<OtherNames>FamMem3</OtherNames>
<DOB>01-01-98</DOB>
<PhotoFileName xsi:nil="true" />
</tblInsurees>
SO is it possible that somehow I can pass an ID as a parameter and I can just display the rest of the information like name and dob etc on my screen?
Here is a complete example with source. You just to get the File using
File file = new File(Environment.getExternalStorageDirectory()
+ "your_path/your_xml.xml");
Then do the further processing.
If you need example for different types of XML Parsers you can download complete example from here.

Android: Is it more efficient to use a text file or an XML file to store static data

I have some reference data in a text file (~5MB) that I want to use with might android application.
The file is of the format:
1|a|This is line 1a
1|b|This is line 1b
2|a|This is line 2a
2|b|This is line 2b
2|c|This is line 2c
What I want to know is the most efficient way (less memory, fast, size etc.) to use this file within my application.
a.) Should I save the file as a raw resource and open and read the whole file whenever I need a certain line.
b.) Should I convert the file to XML and use XPath to query the file when ever I need to look up a value
<!--sample XML -->
<data>
<line number="1">
<entry name="a">This is line 1 a</entry>
</line>
</data>
c.) Should I just copy & paste the whole file as a static string array in the application and use that.
... any other suggestions are welcome.
[EDIT]
I will also need to search this file and jump to arbitrary keywords e.g. "line 1a".
XML will always take longer to read than simple text or CSV files. What XML gives you in the tradeoff is a highly structured and reliable way of storing and retrieving data. XML files are, as you can see in the examples above, a good 2-3x larger than the data they actually contain.
If you're sure that you're never going to run into the "delimiter" character in your simple text file, then that would probably work just fine, purely from a file speed perspective.
You have not provided enough information to answer this question. However, if I were a betting man, the answer is probably "none of the above".
I will also need to search this file
What does this mean? You are searching by some string key? By some regular expression? By a SQL-style query string where certain portions of a line are interpreted as integers versus strings versus something else? By a Google search-style string?
Each of those answers probably dictates a different technology for storing this information.
I will also need to...jump to arbitrary lines.
Why? How are you determining which "arbitrary lines" you are "jump"ing to: key? line number? byte offset? search results? something else?
And, of course, there are other questions, like:
How often is this data updated?
How is this data updated: new version of the app? download the whole file? download deltas/diffs? something else?
Is the data ASCII? UTF-8? Something else?
and so on.
Something that size that must be searched upon suggests "use a SQLite database", but some of the other answers might steer away from that solution.
If you are talking about very small amounts of data, the Android XML compiler can produce very efficient binary representations for you that you can access just like XML. On the other hand if the data is very large at all, and you need arbitrary queries, I would expect SQLlite to win out on performance (as well as flexibility). A small benchmark should be easy to write and would give you a good idea as to the basic tradeoffs involved.
Flat-files would be a last option, imo, but could work if the file isn't very large.
If you define efficiency as (less memory, fast, size etc.), a flat or delimited file will be faster to load and save.
However, people use XML because they are willing to trade some of that speed for XML's greater flexibility and ease of use.

Categories

Resources