XmlDocument Constructores
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Inicializa una nueva instancia de la clase XmlDocument.
Sobrecargas
| Nombre | Description |
|---|---|
| XmlDocument() |
Inicializa una nueva instancia de la clase XmlDocument. |
| XmlDocument(XmlImplementation) |
Inicializa una nueva instancia de la |
| XmlDocument(XmlNameTable) |
Inicializa una nueva instancia de la |
XmlDocument()
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
Inicializa una nueva instancia de la clase XmlDocument.
public:
XmlDocument();
public XmlDocument();
Public Sub New ()
Ejemplos
A continuación se muestra un ejemplo de validación en tiempo de carga. Se pasa una validación XmlReader de definición de tipo de documento (DTD) al Load método y se proporciona un ValidationEventHandler para notificar a los usuarios cualquier error de validación. En este ejemplo se encuentra un error de validación, pero el documento todavía está cargado. Como alternativa, puede definir una validación XmlReader para iniciar una excepción y detener el proceso de carga cuando se encuentra un error de validación sin especificar .ValidationEventHandler Para obtener más información sobre la validación de datos XML, vea la sección Comentarios de la XmlReader página de referencia.
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
En el ejemplo se usa el bookDTD.xml archivo como entrada.
<!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>
Consulte también
Se aplica a
XmlDocument(XmlImplementation)
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
Inicializa una nueva instancia de la XmlDocument clase con el especificado 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)
Parámetros
que XmlImplementation se va a usar.
Se aplica a
XmlDocument(XmlNameTable)
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
- Source:
- XmlDocument.cs
Inicializa una nueva instancia de la XmlDocument clase con el especificado 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)
Parámetros
- nt
- XmlNameTable
que XmlNameTable se va a usar.