简体   繁体   中英

How to read local country phone codes xml in titanium alloy

In my application I get the country code using Titanium.Locale.getCurrentCountry(); , I then want to match this country code with this xml : https://code.google.com/p/country-phone-codes/ to find the corresponding country name and phone code. I am using titanium alloy so where should I put this xml in my project and how can I parse this xml to get the country name and phone code required ?

I would just convert this to JSON (here is a fiddle, I did it for you) and put it inside a file called countries.js , put this file inside your app/lib/ folder (create it if it does not exist) and then call it from code like this:

var countries = require('countries');
// Lookup the country name and phone code by country code
var name = countries['us'].name;
var phoneCode = countries['us'].phoneCode;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM