메뉴 닫기

[ C# ] XML 쓰고 읽기

XML을 읽고 쓰는 소스

        ///
        /// XML 생성
        ///

private void CreateXML() { // 생성할 XML 파일 경로와 이름, 인코딩 방식을 설정합니다. XmlTextWriter textWriter = new XmlTextWriter(@”C:\example.xml”, Encoding.UTF8); // 들여쓰기 설정 textWriter.Formatting = Formatting.Indented; // 문서에 쓰기를 시작합니다. textWriter.WriteStartDocument(); // 루트 설정 textWriter.WriteStartElement(“root”); // 노드와 값 설정 textWriter.WriteStartElement(“root_a”); textWriter.WriteString(“a”); textWriter.WriteEndElement(); // 노드 안에 하위 노드 설정 textWriter.WriteStartElement(“root_b”); textWriter.WriteStartElement(“b”); textWriter.WriteString(“b”); textWriter.WriteEndElement(); textWriter.WriteStartElement(“bb”); textWriter.WriteString(“bb”); textWriter.WriteEndElement(); textWriter.WriteEndElement(); textWriter.WriteStartElement(“root_c”); textWriter.WriteString(“1”); textWriter.WriteEndElement(); textWriter.WriteEndElement(); textWriter.WriteEndDocument(); textWriter.Close(); } ///

        /// XML 파일 읽기
        ///

private void ReadXML() { try { XmlDocument xmldoc = new XmlDocument(); xmldoc.Load(@”C:\example.xml”); XmlElement root = xmldoc.DocumentElement; // 노드 요소들 XmlNodeList nodes = root.ChildNodes; // 노드 요소의 값을 읽어 옵니다. foreach (XmlNode node in nodes) { switch (node.Name) { case “root_a”: string a = node.InnerText; break; case “root_b”: string b = node[“b”].InnerText; string bb = node[“bb”].InnerText; break; case “root_c”: int c = int.Parse(node.InnerText); break; } } } catch (IOException ex) { Console.WriteLine(ex.ToString()); } } 출처: http://shine10e.tistory.com/79 [열이 Blog : )]

23 Comments

  1. Janyce Swihart

    I simply want to mention I am just newbie to blogging and honestly enjoyed this web page. Very likely I’m want to bookmark your website . You really come with great article content. Thanks a lot for sharing your web page.

  2. CBD Cream

    Wow! This could be one particular of the most helpful blogs We’ve ever arrive across on this subject. Basically Excellent. I’m also an expert in this topic therefore I can understand your effort.

  3. More Bonuses

    Oh my goodness! an amazing post man. Thanks Nevertheless I am experiencing issue with ur rss. Don?t know why Not able to subscribe to it. Is there any person obtaining similar rss problem? Any person who understands kindly respond. Thnkx

  4. cbd oil sale ny

    This is the right blog for anyone who intends to find out about this subject. You recognize a lot its virtually hard to argue with you (not that I actually would want?HaHa). You definitely put a brand-new spin on a topic thats been discussed for several years. Excellent things, simply wonderful!

  5. treat-its cbd dog treats

    Good blog post. I find out something more challenging on different blogs daily. It will always be promoting to check out content from other writers and practice a something from their shop. I?d choose to utilize some with the web content on my blog whether you don?t mind. Natually I?ll give you a web link on your web blog. Many thanks for sharing.

  6. hemp bombs mega dose cbd capsules review

    There are absolutely a great deal of information like that to take into account. That is a terrific indicate bring up. I provide the thoughts over as basic motivation however clearly there are questions like the one you bring up where the most vital thing will be operating in straightforward good faith. I don?t know if ideal practices have arised around points like that, but I make certain that your work is plainly recognized as a level playing field. Both boys as well as women feel the influence of simply a moment?s satisfaction, for the rest of their lives.

  7. Lincoln Mcgown

    The next time I check out a blog, I hope that it does not disappoint me as long as this. I suggest, I understand it was my option to check out, however I in fact believed youd have something intriguing to say. All I hear is a number of whimpering concerning something that you might repair if you werent also active looking for focus.

  8. Oren Durch

    The next time I read a blog site, I hope that it does not dissatisfy me as high as this one. I indicate, I recognize it was my choice to check out, but I really thought youd have something intriguing to state. All I listen to is a bunch of grumbling regarding something that you might fix if you werent too busy looking for focus.

  9. hop over to this site

    I?m pleased, I should say. Really seldom do I encounter a blog site that?s both informative and also amusing, and also let me inform you, you have struck the nail on the head. Your concept is superior; the issue is something that inadequate individuals are speaking smartly around. I am very delighted that I came across this in my look for something connecting to this.

  10. had me going

    The next time I review a blog site, I wish that it does not dissatisfy me as much as this. I imply, I understand it was my selection to review, but I really thought youd have something fascinating to state. All I listen to is a lot of yawping about something that you could take care of if you werent as well active searching for focus.

댓글 남기기

이메일은 공개되지 않습니다.