XmlDocument 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
XmlDocument 클래스의 새 인스턴스를 초기화합니다.
오버로드
| Name | Description |
|---|---|
| XmlDocument() |
XmlDocument 클래스의 새 인스턴스를 초기화합니다. |
| XmlDocument(XmlImplementation) |
지정된 클래스를 사용하여 클래스의 |
| XmlDocument(XmlNameTable) |
지정된 클래스를 사용하여 클래스의 |
XmlDocument()
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
XmlDocument 클래스의 새 인스턴스를 초기화합니다.
public:
XmlDocument();
public XmlDocument();
Public Sub New ()
예제
다음은 로드 시간 유효성 검사의 예입니다. DTD(문서 형식 정의) 유효성 XmlReader 검사가 메서드에 Load 전달되고 ValidationEventHandler 유효성 검사 오류를 사용자에게 알리기 위해 제공됩니다. 이 예제에서는 유효성 검사 오류가 발견되었지만 문서는 여전히 로드됩니다. 또는 유효성 검사 XmlReader 오류가 발견되면 예외를 throw하고 로드 프로세스를 중지하도록 유효성 검사를 정의할 ValidationEventHandler수 있습니다. XML 데이터의 유효성을 검사하는 방법에 대한 자세한 내용은 참조 페이지의 설명 섹션을 XmlReader 참조하세요.
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.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 파일을 입력으로 사용합니다.
<!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)
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
지정된 클래스를 사용하여 클래스의 XmlDocument 새 인스턴스를 초기화합니다 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)
매개 변수
XmlImplementation 사용할 수 있습니다.
적용 대상
XmlDocument(XmlNameTable)
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
지정된 클래스를 사용하여 클래스의 XmlDocument 새 인스턴스를 초기화합니다 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 사용할 수 있습니다.