메뉴 건너뛰기

라이온하트 2nd edition

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

조회 수 135145 추천 수 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
번호 분류 제목 글쓴이 날짜 조회 수
45 C# C# 동영상 녹화 LionHeart 2014.05.21 126555
44 Information 나눔글꼴 웹폰트 LionHeart 2014.05.04 110483
43 IOS 유저 기기 고유 ID [SystemInfo.deviceUniqueIdentifier] file badung007 2014.04.25 106037
42 C# 웹캠 영상출력 LionHeart 2014.03.31 157154
41 Android [유니티3D엔진] 유니티 Scene 로딩 badung007 2014.03.21 77009
40 Computer Free Proxy List LionHeart 2014.02.04 89616
39 C# 초간단 FTP LionHeart 2014.01.29 112004
38 C# C# Simple FTP Class LionHeart 2014.01.29 169723
37 C# 자료형 변환 Convert.ToDouble 과 double.parse 의 차이 1 badung007 2014.01.16 87851
36 Computer icon 만들기 LionHeart 2014.01.13 83035
35 OS Windows 2012 설치방법에 관한 문서 LionHeart 2013.12.27 135672
34 Android [유니티3D엔진] 유니티 최적화 _ 프레임 줄이기 badung007 2013.12.06 98346
33 Android [유니티3D엔진] C# 어레이리스트 dat 파일 로드 및 저장 (바이너리 파일로 변환) badung007 2013.12.05 75539
» Android [유니티3D엔진] C# 어레이리스트 xml 파일 저장 badung007 2013.12.04 135145
31 C# C#에서 list Class 사용방법 1 LionHeart 2013.12.03 103967
30 Computer zip 압축파일 비밀번호 Crack 1 file LionHeart 2013.12.01 118143
29 OS 네트워크 스니핑 도구(엄청 강력함) file LionHeart 2013.12.01 72785
28 Android [유니티3D엔진] NGUI 해상도 비율적으로 풀화면 badung007 2013.11.29 81627
27 C# C# FTP 종합 LionHeart 2013.11.04 211213
26 C# FTP에서 파일 삭제하는 방법 LionHeart 2013.11.04 107030
Board Pagination ‹ Prev 1 ... 3 4 5 6 7 8 9 10 11 12 Next ›
/ 12