메뉴 건너뛰기

라이온하트 2nd edition

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

조회 수 135098 추천 수 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;
    }




  1. [CentOS] NTFS마운트하기

  2. CentOS 6.x 설치 시 BIOS RAID metadata 문제

  3. XE 속도개선 (XE 캐시파일 초기화 시간 줄이는 팁) - 다국어 제거

  4. Chrome on Centos

  5. INSTALLING NVIDIA LINUX DRIVERS IN A XEN ENABLED KERNEL

  6. Install NVIDIA Drivers in XEN Kernel

  7. XE 속도 개선팁 모음

  8. memcached 설치 및 설정

  9. XE 쇼핑몰 솔루션

  10. 알아두면 유용한 무료사이트 20선

  11. Ubuntu, HWP 2008 installation on x86 and x64 (only Link)

  12. USB 저장장치에 의한 데이터 유출 방지 방법

  13. 파일검색 루틴 (개발용)

  14. Realtek 8723be-bt 무선랜 드라이버 (한성 u44x )

  15. [LINK] 윈도우 8 관리자 권한 설정으로 항상 관리자 권한 얻기

  16. C# How to make a simple MP3 player in C#

  17. [ 유니티3D엔진 ] FPS 프레임 조절

  18. [ OS X ] 폴더 숨김파일 표시

  19. C#에서 무료 TTS 사용하기

  20. 우분투 sudo 비밀번호 안물어보게 하기

Board Pagination ‹ Prev 1 ... 3 4 5 6 7 8 9 10 11 12 Next ›
/ 12