XmlDocument XmlDocument XmlDocument XmlDocument Constructors

정의

오버로드

XmlDocument() XmlDocument() XmlDocument()

XmlDocument 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class.

XmlDocument(XmlImplementation) XmlDocument(XmlImplementation) XmlDocument(XmlImplementation) XmlDocument(XmlImplementation)

지정된 XmlDocument를 사용하여 XmlImplementation 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class with the specified XmlImplementation.

XmlDocument(XmlNameTable) XmlDocument(XmlNameTable) XmlDocument(XmlNameTable) XmlDocument(XmlNameTable)

지정된 XmlDocument를 사용하여 XmlNameTable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class with the specified XmlNameTable.

XmlDocument() XmlDocument() XmlDocument()

XmlDocument 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class.

public:
 XmlDocument();
public XmlDocument ();
Public Sub New ()

예제

다음은 로드할 때 유효성 검사의 예입니다.The following is an example of load-time validation. 문서 유형 정의 (DTD) 유효성 XmlReader 에 전달 되는 Load 메서드 및 ValidationEventHandler 유효성 검사 오류가 발생 하는 사용자에 게 제공 됩니다.A document type definition (DTD) validating XmlReader is passed to the Load method and a ValidationEventHandler is provided to notify users of any validation errors. 이 예제의 유효성 검사 오류가 발견 되 이지만 문서 계속 로드 합니다.In this example a validation error is found, but the document is still loaded. 유효성 검사를 정의할 수 있습니다 또는 XmlReader 예외를 throw 하지를 지정 하 여 유효성 검사 오류가 발견 되 면 로드 프로세스를 중지 하는 ValidationEventHandler합니다.Alternatively, you can define a validating XmlReader to throw an exception and stop the load process when a validation error is found by not specifying the ValidationEventHandler. XML 데이터 유효성 검사에 대한 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.For more information about validating XML data, see the Remarks section of the XmlReader reference page.

#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
using namespace System::Xml::Schema;

ref class XmlDocumentSample
{
private:
	static XmlReader^ reader;
	static String^ filename = "bookdtd.xml";

	// Display the validation error.
	static void ValidationCallback(Object^ sender, ValidationEventArgs^ args)
	{
		Console::WriteLine("Validation error loading: {0}", filename);
		Console::WriteLine(args->Message);
	}

public:
	static void Main()
	{
		ValidationEventHandler^ eventHandler = gcnew ValidationEventHandler(XmlDocumentSample::ValidationCallback);

		try
		{
			// Create the validating reader and specify DTD validation.
			XmlReaderSettings^ settings = gcnew XmlReaderSettings();
                        settings->DtdProcessing = DtdProcessing::Parse;
			settings->ValidationType = ValidationType::DTD;
			settings->ValidationEventHandler += eventHandler;

			reader = XmlReader::Create(filename, settings);

			// Pass the validating reader to the XML document.
			// Validation fails due to an undefined attribute, but the 
			// data is still loaded into the document.
			XmlDocument^ doc = gcnew XmlDocument();
			doc->Load(reader);
			Console::WriteLine(doc->OuterXml);
		}
		finally
		{
			if (reader != nullptr)
				reader->Close();
		}
	}
};

int main()
{
	XmlDocumentSample::Main();
	return 0;
}
using System;
using System.Xml;
using System.Xml.Schema;

namespace Microsoft.Samples.Xml
{
    sealed class XmlDocumentSample
    {
        private XmlDocumentSample() { }

        static XmlReader reader;
        static String filename = "bookdtd.xml";

        public static void Main()
        {

            ValidationEventHandler eventHandler = new ValidationEventHandler(XmlDocumentSample.ValidationCallback);

            try
            {
                // Create the validating reader and specify DTD validation.
                XmlReaderSettings settings = new XmlReaderSettings();
                settings.DtdProcessing = DtdProcessing.Parse;
                settings.ValidationType = ValidationType.DTD;
                settings.ValidationEventHandler += eventHandler;

                reader = XmlReader.Create(filename, settings);

                // Pass the validating reader to the XML document.
                // Validation fails due to an undefined attribute, but the 
                // data is still loaded into the document.
                XmlDocument doc = new XmlDocument();
                doc.Load(reader);
                Console.WriteLine(doc.OuterXml);
            }
            finally
            {
                if (reader != null)
                    reader.Close();
            }
        }

        // Display the validation error.
        private static void ValidationCallback(object sender, ValidationEventArgs args)
        {
            Console.WriteLine("Validation error loading: {0}", filename);
            Console.WriteLine(args.Message);
        }
    }
}
Option Explicit On
Option Strict On

Imports System
Imports System.Xml
Imports System.Xml.Schema

Namespace Microsoft.Samples.Xml

    NotInheritable Class XmlDocumentSample

        Private Sub New()

        End Sub

        Shared reader As XmlReader
        Shared filename As String = "bookdtd.xml"

        Public Shared Sub Main()


            Dim eventHandler As New ValidationEventHandler(AddressOf XmlDocumentSample.ValidationCallback)

            Try

                ' Create the validating reader and specify DTD validation.
                Dim settings As New XmlReaderSettings()
                settings.DtdProcessing = DtdProcessing.Parse
                settings.ValidationType = ValidationType.DTD
                AddHandler settings.ValidationEventHandler, eventHandler

                reader = XmlReader.Create(filename, settings)

                ' Pass the validating reader to the XML document.
                ' Validation fails due to an undefined attribute, but the 
                ' data is still loaded into the document.
                Dim doc As New XmlDocument()
                doc.Load(reader)
                Console.WriteLine(doc.OuterXml)
            
            Finally

                If Not (reader Is Nothing) Then
                    reader.Close()
                End If

            End Try

        End Sub

        ' Display the validation error.
        Private Shared Sub ValidationCallback(ByVal sender As Object, ByVal args As ValidationEventArgs)
            Console.WriteLine("Validation error loading: {0}", filename)
            Console.WriteLine(args.Message)
        End Sub

    End Class
End Namespace

이 예제에서는 bookDTD.xml 파일을 입력으로 사용합니다.The example uses the bookDTD.xml file as input.

<!DOCTYPE bookstore [
  <!ELEMENT bookstore (book)*> 
  <!ELEMENT book (title,author,price)>
  <!ATTLIST book genre CDATA #REQUIRED>
  <!ELEMENT title (#PCDATA)>
  <!ELEMENT author (#PCDATA)>
  <!ELEMENT price (#PCDATA)>]>
<bookstore>
  <book genre="fantasy"  ISBN="2-3631-4">
    <title>Oberon's Legacy</title>
    <author>Corets, Eva</author>
    <price>5.95</price>
  </book>
</bookstore>
추가 정보

XmlDocument(XmlImplementation) XmlDocument(XmlImplementation) XmlDocument(XmlImplementation) XmlDocument(XmlImplementation)

지정된 XmlDocument를 사용하여 XmlImplementation 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class with the specified XmlImplementation.

protected public:
 XmlDocument(System::Xml::XmlImplementation ^ imp);
protected internal XmlDocument (System.Xml.XmlImplementation imp);
new System.Xml.XmlDocument : System.Xml.XmlImplementation -> System.Xml.XmlDocument
Protected Friend Sub New (imp As XmlImplementation)

매개 변수

imp
XmlImplementation XmlImplementation XmlImplementation XmlImplementation

사용할 XmlImplementation입니다.The XmlImplementation to use.

XmlDocument(XmlNameTable) XmlDocument(XmlNameTable) XmlDocument(XmlNameTable) XmlDocument(XmlNameTable)

지정된 XmlDocument를 사용하여 XmlNameTable 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the XmlDocument class with the specified XmlNameTable.

public:
 XmlDocument(System::Xml::XmlNameTable ^ nt);
public XmlDocument (System.Xml.XmlNameTable nt);
new System.Xml.XmlDocument : System.Xml.XmlNameTable -> System.Xml.XmlDocument
Public Sub New (nt As XmlNameTable)

매개 변수

nt
XmlNameTable XmlNameTable XmlNameTable XmlNameTable

사용할 XmlNameTable입니다.The XmlNameTable to use.

적용 대상