Udostępnij za pośrednictwem


Metoda XMLNode.LoadXml — (XmlElement)

Wypełnia XMLNode formant z danymi z XmlElement.

Przestrzeń nazw:  Microsoft.Office.Tools.Word
Zestaw:  Microsoft.Office.Tools.Word (w Microsoft.Office.Tools.Word.dll)

Składnia

'Deklaracja
Sub LoadXml ( _
    xmlElement As XmlElement _
)
void LoadXml(
    XmlElement xmlElement
)

Parametry

Uwagi

Ta metoda nie dodaje dodatkowe XMLNode formanty lub usuń niepotrzebne XMLNode formanty z dokumentu.

Ta metoda aktualizuje wszystkie atrybuty XMLNode kontroli.

Przykłady

Następujący kod w przykładzie wykorzystano LoadXml metodę, aby wypełnić XMLNode z danymi z XmlElement.Przykład odczytuje zawartość pliku XML do StreamReader, to ładuje StreamReader do XmlDocument, a następnie inicjuje XmlElement , oznaczającą pierwszy element podrzędny w XmlDocument.To XmlElement są używane do xmlElement parametr LoadXml metoda.W tym przykładzie założono, że bieżący dokument zawiera XMLNode o nazwie CustomerLastNameNode , który odpowiada pierwszemu elementowi potomnemu w skojarzony schemat.W tym przykładzie również założono, że plik XML o nazwie Customers.xml, który spełnia skojarzony schemat, w głównym katalogu D.

Private Sub LoadXmlFromXmlElement()
    Dim xmlPath As String = "D:\Customers.xml"
    Dim xmlStreamReader As New System.IO.StreamReader(xmlPath)
    Dim xmlDoc As New System.Xml.XmlDocument()

    xmlDoc.Load(xmlStreamReader)
    Dim firstElement As System.Xml.XmlElement = _
        CType(xmlDoc.DocumentElement.FirstChild, System.Xml.XmlElement)
    Me.CustomerLastNameNode.LoadXml(firstElement)
End Sub
private void LoadXmlFromXmlElement()
{
    string xmlPath = @"D:\Customers.xml";
    System.IO.StreamReader xmlStreamReader = 
        new System.IO.StreamReader(xmlPath);
    System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();

    xmlDoc.Load(xmlStreamReader);
    System.Xml.XmlElement firstElement =
        (System.Xml.XmlElement)xmlDoc.DocumentElement.FirstChild;
    this.CustomerLastNameNode.LoadXml(firstElement);
}

Zabezpieczenia programu .NET Framework

Zobacz też

Informacje

XMLNode Interfejs

Przeciążenie LoadXml

Przestrzeń nazw Microsoft.Office.Tools.Word