Freigeben über


XMLNode.LoadXml Method (XmlElement)

Populates an XMLNode control with data from an XmlElement.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Syntax

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

Parameters

Remarks

This method does not add additional XMLNode controls or delete unnecessary XMLNode controls from the document.

This method updates all attributes of the XMLNode control.

Examples

The following code example uses the LoadXml method to fill an XMLNode with data from an XmlElement. The example reads the contents of an XML file into a StreamReader, loads this StreamReader into an XmlDocument, and then initializes an XmlElement that represents the first child element in the XmlDocument. This XmlElement is then used for the xmlElement parameter of the LoadXml method. This example assumes that the current document contains an XMLNode named CustomerLastNameNode that corresponds to the first child element in the associated schema. This example also assumes that an XML file named Customers.xml, which conforms to the associated schema, exists at the root of the D directory.

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);
}

.NET Framework Security

See Also

Reference

XMLNode Interface

LoadXml Overload

Microsoft.Office.Tools.Word Namespace