게시판 즐겨찾기
편집
드래그 앤 드롭으로
즐겨찾기 아이콘 위치 수정이 가능합니다.
XML 파일 불러오기 관련 질문 합니다 (feat.C#)
게시물ID : programmer_19784짧은주소 복사하기
작성자 : Benny
추천 : 0
조회수 : 531회
댓글수 : 4개
등록시간 : 2017/02/14 08:19:03
옵션
  • 창작글
  • 베스트금지
  • 베오베금지
  • 본인삭제금지
  • 외부펌금지
예를들어, 이렇게 xml 파일에서 supplier-labels 혹은 workplace-labels 중 하나의 labels 만 화면에 불러 오려고 합니다.
C# 코드를 실행하면 xml 파일의 경로를 입력 하라고 하고 그 다음에 supplier-labels는 1번 workplace-labels는 2번으로 본다면 1을 입력 후
supplier-labels 의 내용만 불러 오려고 합니다. 
어떻게 해야 할지 감이 안오네요 ㅠㅠ

-- xml --

<supplier-labels>
<Products1></Product1>
<Products1></Product1>
<Products1></Product1>
<Products1></Product1>
</supplier-labels>

<workplace-labels>
<Products1></Product1>
<Products1></Product1>
<Products1></Product1>
</workplace-labels>

-- C# --

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

// Namespaces added manually
using System.Xml;           // XmlReader, XmlDocument and XmlReaderSetting classes
using System.Xml.Schema;    // XmlSchemaValidationFlags class
using System.IO;            // File class

namespace DisplayChessGame
{
    class DisplayChess
    {
        // Private member variables
        private static string xmlFile = "";
        private static bool valid_xml = true;

        static void Main(string[] args)
        {
            try
            {
                // Display a title
                Console.WriteLine("WHMIS 2015 Label Information\n----------------------------\n");    

                // Get the name of the XML file 
                if (args.Count() > 0 && File.Exists(args[0]))
                {
                    // Getting XML file name from the command line
                    xmlFile = args[0];
                }
                else
                {
                    // Ask the user to input the file name 
                    bool invalidFile = true;
                    do
                    {
                        Console.Write("Enter the path + name of your XML file: ");
                        xmlFile = Console.ReadLine();

                        if (!File.Exists(xmlFile))
                            Console.WriteLine("ERROR: The file '{0}' can't be found!", xmlFile);
                        else
                            invalidFile = false;

                    } while ( invalidFile );

                    // Print a blank line
                    Console.WriteLine(); 
                }

                // Set the validation settings
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.ValidationType = ValidationType.Schema;
                settings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
                settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessInlineSchema;
                ValidationEventHandler handler
                        = new ValidationEventHandler(ValidationCallback);
                settings.ValidationEventHandler += handler;
                settings.ValidationFlags |= XmlSchemaValidationFlags.ProcessSchemaLocation;

                // Create the XmlReader object and read/validate the XML file
                XmlReader reader = XmlReader.Create(xmlFile, settings);

                // Load the xml into the DOM
                XmlDocument doc = new XmlDocument();
                doc.Load(reader);

                if (valid_xml)
                {
                ???????????????????????????????????
    ???????????????????????????????????
   ???????????????????????????????????
                }
            }
            catch (XmlException ex)
            {
                Console.WriteLine("ERROR: " + ex.Message);
            }

            // Hold the console window open until a key is pressed
            Console.WriteLine("Press any key to quit.");
            Console.ReadKey();

        } // end Main()


        // Callback method to display validation errors and warnings
        private static void ValidationCallback(object sender, ValidationEventArgs args)
        {
            if (args.Severity == XmlSeverityType.Warning)
                Console.WriteLine("WARNING: " + args.Message);
            else
            {
                Console.WriteLine("SCHEMA ERROR: " + args.Message);
                valid_xml = false;
            }
        } // end ValidationCallback()


    } // end class
} // end namespace

제가 물음표로 해놓은 공간에 코드를 만들어야 하는데 도저히 감이 안오네요 ㅠㅠ
전체 추천리스트 보기
새로운 댓글이 없습니다.
새로운 댓글 확인하기
글쓰기
◀뒤로가기
PC버전
맨위로▲
공지 운영 자료창고 청소년보호