| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Xml;
- namespace JC.Unity.Picker {
- public class LocationParseComponent : MonoBehaviour {
- [SerializeField] TextAsset xmlFileText;
- LocationParser locationParser;
- public static LocationParseComponent ins;
- void Awake() {
- ins = this;
- locationParser = new LocationParser(xmlFileText);
- }
- void OnDestroy() {
- if (ins == this) ins = null;
- }
- public Tuple<string, string, string> ParseNameByCode(string countryCode, string stateCode, string cityCode) {
- string countryName = "";
- string stateName = "";
- string cityName = "";
- XmlNodeList stateNodeList = null;
- XmlNodeList cityNodeList = null;
- foreach (var countryNode in locationParser.CountryRegionList) {
- if (countryNode.Attributes["Code"].Value == countryCode) {
- countryName = countryNode.Attributes["Name"].Value;
- stateNodeList = countryNode.SelectNodes("State");
- break;
- }
- }
- if (stateNodeList != null) {
- for (int i = 0; i < stateNodeList.Count; i++) {
- XmlNode stateNode = stateNodeList[i];
- XmlAttribute CodeAtb = stateNode.Attributes["Code"];
- if (CodeAtb != null) {
- if (stateCode == CodeAtb.Value) {
- XmlAttribute NameAtb = stateNode.Attributes["Name"];
- if (NameAtb != null) {
- stateName = NameAtb.Value;
- cityNodeList = stateNode.SelectNodes("City");
- break;
- }
- }
- } else if (CodeAtb == null && string.IsNullOrEmpty(stateCode)) {
- cityNodeList = stateNode.SelectNodes("City");
- break;
- }
- }
- }
- if (cityNodeList != null) {
- for (int i = 0; i < cityNodeList.Count; i++) {
- XmlNode cityNode = cityNodeList[i];
- XmlAttribute CodeAtb = cityNode.Attributes["Code"];
- if (CodeAtb != null) {
- if (cityCode == CodeAtb.Value) {
- XmlAttribute NameAtb = cityNode.Attributes["Name"];
- if (NameAtb != null) {
- cityName = NameAtb.Value;
- break;
- }
- }
- }
- }
- }
- return new Tuple<string, string, string>(countryName, stateName, cityName);
- }
- }
- }
|