XElement.WriteTo(XmlWriter) XElement.WriteTo(XmlWriter) XElement.WriteTo(XmlWriter) XElement.WriteTo(XmlWriter) Method

정의

이 요소를 XmlWriter에 씁니다.Write this element to an XmlWriter.

public:
 override void WriteTo(System::Xml::XmlWriter ^ writer);
public override void WriteTo (System.Xml.XmlWriter writer);
override this.WriteTo : System.Xml.XmlWriter -> unit
Public Overrides Sub WriteTo (writer As XmlWriter)

매개 변수

writer
XmlWriter XmlWriter XmlWriter XmlWriter

이 메서드가 쓸 XmlWriter입니다.An XmlWriter into which this method will write.

예제

다음 예제에서는 쓰는 방법을 보여 줍니다.는 XElementXmlWriter합니다.The following example shows how to write an XElement to an XmlWriter. 이 예제에서는 XML 선언을 작성 하지 않은 참고 합니다.Note that the example did not write an XML declaration.

StringBuilder sb = new StringBuilder();  
XmlWriterSettings xws = new XmlWriterSettings();  
xws.OmitXmlDeclaration = true;  
xws.Indent = true;  

using (XmlWriter xw = XmlWriter.Create(sb, xws)) {  
    xw.WriteStartElement("Root");  

    XElement child1 = new XElement("Child",  
        new XElement("GrandChild", "some content")  
    );  
    child1.WriteTo(xw);  

    XElement child2 = new XElement("AnotherChild",  
        new XElement("GrandChild", "different content")  
    );  
    child2.WriteTo(xw);  

    xw.WriteEndElement();  
}  

Console.WriteLine(sb.ToString());  
Dim sb As StringBuilder = New StringBuilder()  
Dim xws As XmlWriterSettings = New XmlWriterSettings()  
xws.OmitXmlDeclaration = True  
xws.Indent = True  

Using xw = XmlWriter.Create(sb, xws)  
    xw.WriteStartElement("Root")  
    Dim child1 As XElement = _  
        <Child>  
            <GrandChild>some content</GrandChild>  
        </Child>  
    child1.WriteTo(xw)  
    Dim child2 As XElement = _   
        <AnotherChild>  
            <GrandChild>different content</GrandChild>  
        </AnotherChild>  
    child2.WriteTo(xw)  
    xw.WriteEndElement()  
End Using  

Console.WriteLine(sb.ToString())  

이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:

<Root>  
  <Child>  
    <GrandChild>some content</GrandChild>  
  </Child>  
  <AnotherChild>  
    <GrandChild>different content</GrandChild>  
  </AnotherChild>  
</Root>  

적용 대상

추가 정보