메뉴 건너뛰기

라이온하트 2nd edition

홈페이지를 새롭게 리뉴얼합니다.

조회 수 135160 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

   Sm_data_xml.cs


   XmlDocument xmlFile = new XmlDocument();


   XML로드(구현완료)


   public XmlNodeList xmlLoad(string file_Name)
   {
        GlobalVars.instance.setGxml_Processing_chk(false);
        try
        {
            xmlFile.Load( Application.dataPath + "/Sm_data_xml/" + file_Name + ".xml" );
            //XmlNodeList list = xmlFile.SelectNodes("/sm_data/" + record_Name);
            XmlNodeList list = xmlFile.SelectNodes("/sm_data/record");
            return list;
        }
        //File not found
        catch (System.IO.FileNotFoundException e)
        {
            Debug.Log( "Could not found!" + e.Message);
            return null;
        }
        //File error
        catch (System.Xml.XmlException e)
        {
            Debug.Log( "error!" + e.Message );
            FileInfo errorLog = null;
            StreamWriter writer = null;

            //Create or read file
            errorLog = new FileInfo(Application.dataPath + "/Sm_data_xml/" + System.DateTime.Now.ToString("yyyy-MM-dd") + ".txt");
            writer = errorLog.AppendText();

            //Print the error message, time
            writer.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm"));
            writer.WriteLine(e.Message);
            writer.WriteLine();

            writer.Close();
            return null;
        }
    }


   XML세이브 (간단하게 구현)


    public void xmlSave(string file_Name)
    {
       
        xmlFile.AppendChild(xmlFile.CreateXmlDeclaration("1.0", "utf-8", "yes"));
       
        // Root Node
        XmlNode rootNode = xmlFile.CreateNode(XmlNodeType.Element, "sm_data", string.Empty);
        xmlFile.AppendChild(rootNode);

        for (int i = 0; i < 5; i++)
        {
            //child Node
            XmlNode childNode = xmlFile.CreateNode(XmlNodeType.Element, "record", string.Empty);
            rootNode.AppendChild(childNode);
            XmlElement ml_level = xmlFile.CreateElement("ml_level");
            ml_level.InnerText = "LV1 " + i.ToString();
            childNode.AppendChild(ml_level);

            XmlElement ml_1 = xmlFile.CreateElement("ml_1");
            ml_1.InnerText = "ml_1 " + i.ToString();
            childNode.AppendChild(ml_1);

            XmlElement ml_2 = xmlFile.CreateElement("ml_2");
            ml_2.InnerText = "ml_2 " + i.ToString();
            childNode.AppendChild(ml_2);

            XmlElement ml_3 = xmlFile.CreateElement("ml_3");
            ml_3.InnerText = "ml_3 " + i.ToString();
            childNode.AppendChild(ml_3);

            XmlElement ml_4 = xmlFile.CreateElement("ml_4");
            ml_4.InnerText = "ml_4 " + i.ToString();
            childNode.AppendChild(ml_4);
        }

        xmlFile.Save(Application.dataPath + "/Sm_data_xml/" + file_Name + ".xml");
    }


      쓰고 싶은 곳에서

      
       ///////////////////////////////////////////////////////////////////////////////////////       
       XmlNodeList list = null;
       list = Sm_data_xml.instance.xmlLoad("sm_mlevel_st");
        // null 채크
       if (list != null)
       {
           GlobalVars.instance.setGxml_Processing_chk(true);
       }
       /////////////////////////////////////////////////////////////////////////////////////// 
       
       // update 문에 넣기
       if( GlobalVars.instance.getGxml_Processing_chk() )
       {
           List<Xml_sm_mlevel_st_entry> tmpList = new List<Xml_sm_mlevel_st_entry>();
           foreach (XmlNode recordNode in list)
           {
               // 1. 레코드 끝까지 포문처럼 돈다 한개만 빼고 싶으면 여기서 찾아서 사용

               // 2. 전체를 리스트에 넣고 싶으면 아래와 같이 코드 작성하기
               Xml_sm_mlevel_st_entry entry1 = new Xml_sm_mlevel_st_entry(recordNode["ml_level"].FirstChild.InnerText, recordNode["ml_1"].FirstChild.InnerText, recordNode["ml_2"].FirstChild.InnerText, recordNode["ml_3"].FirstChild.InnerText, recordNode["ml_4"].FirstChild.InnerText);
               tmpList.Add(entry1);
           }
           for (int i = 0; i < list.Count; i++)
           {
               Debug.Log(tmpList[i].getStl1().ToString());
               Debug.Log(tmpList[i].getStl2().ToString());
               Debug.Log(tmpList[i].getStl3().ToString());
               Debug.Log(tmpList[i].getStl4().ToString());
               Debug.Log("----------------------");
           }
           GlobalVars.instance.setGxml_Processing_chk(false);
       }


   // Sm_data_xml.instance.xmlSave( "sm_mlevel_st" );



   // 리스트를 통채로 xml로 만들고 불러오기 (xml 직렬화)


    XmlSerializer serializer = null;
    FileStream stream = null;
    Sm_mlevel_st_entry emp = null;
    string fileName = string.Empty;


    public void XMLSerialize(object emp, string aaa)
    {
        serializer = new XmlSerializer(typeof(Sm_mlevel_st_entry));
        TextWriter writer = new StreamWriter(Application.dataPath + "/Sm_data_xml/" + "filePath" + ".xml");
        serializer.Serialize(writer, emp);
        writer.Close();
    }


    public Sm_mlevel_st_entry XMLDeserialize(string filePath)
    {
        serializer = new XmlSerializer(typeof(Sm_mlevel_st_entry));
        stream = new FileStream(filePath, FileMode.Open);
        emp = (Sm_mlevel_st_entry)serializer.Deserialize(stream);
        stream.Close();

        return emp;
    }




List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
17 Android Unity 타임 함수 badung007 2015.08.08 79084
16 Android Unity 코루틴 명령어 badung007 2015.08.06 84846
15 Android Unity CameraReSize badung007 2015.04.10 75666
14 Android [ 유니티3D엔진 ] 유니티 4.3.4 -> 4.2.2 다운그레이드 badung007 2014.09.20 80158
13 Android [ 유니티3D엔진 ] FPS 프레임 조절 badung007 2014.06.15 129091
12 Android [유니티3D엔진] 유니티 Scene 로딩 badung007 2014.03.21 77017
11 Android [유니티3D엔진] 유니티 최적화 _ 프레임 줄이기 badung007 2013.12.06 98356
10 Android [유니티3D엔진] C# 어레이리스트 dat 파일 로드 및 저장 (바이너리 파일로 변환) badung007 2013.12.05 75547
» Android [유니티3D엔진] C# 어레이리스트 xml 파일 저장 badung007 2013.12.04 135160
8 Android [유니티3D엔진] NGUI 해상도 비율적으로 풀화면 badung007 2013.11.29 81637
7 Android [유니티3D엔진] C# 싱글톤 구현 및 인스턴스 활용 badung007 2013.10.28 94458
6 Android [안드로이드] ProgressDialog 시간 처리 badung007 2013.10.27 101965
5 Android 안드로이드 개발환경의 이해 LionHeart 2013.10.27 110521
4 Android [안드로이드] android:launchMode, singleTop과 singleTask의 차이 badung007 2013.10.26 98652
3 Android [유니티3D엔진] 안드로이드 유니티 연동_JNI badung007 2013.10.26 191256
2 Android [안드로이드] 인터넷 연결 상태 확인 badung007 2013.10.25 76586
1 Android [안드로이드] 단말기 정보 (계정, device, 고유 정보값) 가져오기 badung007 2013.10.25 128307
Board Pagination ‹ Prev 1 Next ›
/ 1