Carga el documento XML desde la cadena especificada.
Espacio de nombres: System.Xml
Ensamblado: System.Xml (en system.xml.dll)

Sintaxis
Visual Basic (Declaración)
Public Overridable Sub LoadXml ( _
xml As String _
)
Dim instance As XmlDocument
Dim xml As String
instance.LoadXml(xml)
public virtual void LoadXml (
string xml
)
public:
virtual void LoadXml (
String^ xml
)
public void LoadXml (
String xml
)
public function LoadXml (
xml : String
)
Parámetros
- xml
Cadena que contiene el documento XML que se va a cargar.

Excepciones
| Tipo de excepción | Condició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. |

Comentarios
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).

Ejemplo
En el ejemplo siguiente se carga XML en un objeto XmlDocument y se guarda en un archivo.
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
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);
}
}
#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 );
}
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

Plataformas
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.

Información de versión
.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

Vea también