Versión imprimible       Enviar     
Evaluar y enviar comentarios

  Encender vista de ancho de banda bajo
Esta página es específica de
Microsoft Visual Studio 2005/.NET Framework 2.0

Hay además otras versiones disponibles para:
XmlDocument.LoadXml (Método)
Carga el documento XML desde la cadena especificada.

Espacio de nombres: System.Xml
Ensamblado: System.Xml (en system.xml.dll)

Visual Basic (Declaración)
Public Overridable Sub LoadXml ( _
    xml As String _
)
Visual Basic (Uso)
Dim instance As XmlDocument
Dim xml As String

instance.LoadXml(xml)
C#
public virtual void LoadXml (
    string xml
)
C++
public:
virtual void LoadXml (
    String^ xml
)
J#
public void LoadXml (
    String xml
)
JScript
public function LoadXml (
    xml : String
)
XAML
No aplicable.

Parámetros

xml

Cadena que contiene el documento XML que se va a cargar.

Tipo de excepciónCondición

XmlException

Se ha producido un error de carga o de análisis en el documento XML. En este caso, el documento se queda vacío.

De forma predeterminada, el método LoadXml no conserva el espacio en blanco ni el espacio en blanco significativo.

Este método no realiza la validación de DTD ni de esquema. Si desea que haya validación, puede crear una instancia de XmlReader de validación mediante la clase XmlReaderSettings y el método Create. Para obtener más información, vea Validación de datos XML con XmlReader.

Este método es una extensión de Microsoft al Modelo de objetos de documento (DOM, Document Object Model).

En el ejemplo siguiente se carga XML en un objeto XmlDocument y se guarda en un archivo.

Visual Basic
Imports System
Imports System.Xml

public class Sample 

  public shared sub Main() 
 
    ' Create the XmlDocument.
    Dim doc as XmlDocument = new XmlDocument()
    doc.LoadXml("<item><name>wrench</name></item>")

   ' Add a price element.
   Dim newElem as XmlElement = doc.CreateElement("price")
   newElem.InnerText = "10.95"
   doc.DocumentElement.AppendChild(newElem)

    ' Save the document to a file and auto-indent the output.
    Dim writer as XmlTextWriter = new XmlTextWriter("data.xml",nothing)
    writer.Formatting = Formatting.Indented
    doc.Save(writer)
  end sub
end class
C#
using System;
using System.Xml;

public class Sample {

  public static void Main() {
 
    // Create the XmlDocument.
    XmlDocument doc = new XmlDocument();
    doc.LoadXml("<item><name>wrench</name></item>");

   // Add a price element.
   XmlElement newElem = doc.CreateElement("price");
   newElem.InnerText = "10.95";
   doc.DocumentElement.AppendChild(newElem);

    // Save the document to a file and auto-indent the output.
    XmlTextWriter writer = new XmlTextWriter("data.xml",null);
    writer.Formatting = Formatting.Indented;
    doc.Save(writer);
  }
}
C++
#using <System.Xml.dll>

using namespace System;
using namespace System::Xml;
int main()
{
   
   // Create the XmlDocument.
   XmlDocument^ doc = gcnew XmlDocument;
   doc->LoadXml( "<item><name>wrench</name></item>" );
   
   // Add a price element.
   XmlElement^ newElem = doc->CreateElement( "price" );
   newElem->InnerText = "10.95";
   doc->DocumentElement->AppendChild( newElem );
   
   // Save the document to a file and auto-indent the output.
   XmlTextWriter^ writer = gcnew XmlTextWriter( "data.xml", nullptr );
   writer->Formatting = Formatting::Indented;
   doc->Save( writer );
}

J#
import System.*;
import System.Xml.*;

public class Sample
{
    public static void main(String[] args)
    {
        // Create the XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<item><name>wrench</name></item>");

        // Add a price element.
        XmlElement newElem = doc.CreateElement("price");
        newElem.set_InnerText("10.95");
        doc.get_DocumentElement().AppendChild(newElem);

        // Save the document to a file and auto-indent the output.
        XmlTextWriter writer = new XmlTextWriter("data.xml", null);
        writer.set_Formatting(Formatting.Indented);
        doc.Save(writer);
    } //main
} //Sample

Windows 98, Windows 2000 Service Pack 4, Windows CE, Windows Millennium, Windows Mobile para Pocket PC, Windows Mobile para Smartphone, Windows Server 2003, Windows XP Media Center, Windows XP Professional x64, Windows XP SP2, Windows XP Starter

Microsoft .NET Framework 3.0 es compatible con Windows Vista, Microsoft Windows XP SP2 y Windows Server 2003 SP1.

.NET Framework

Compatible con: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Compatible con: 2.0, 1.0

XNA Framework

Compatible con: 1.0
© 2009 Microsoft Corporation. Reservados todos los derechos. Términos de uso  |  Marcas Registradas  |  Privacidad
Page view tracker