XmlTextWriter.WriteFullEndElement 方法

定义

关闭一个元素并弹出相应的命名空间范围。Closes one element and pops the corresponding namespace scope.

public:
 override void WriteFullEndElement();
public override void WriteFullEndElement ();
override this.WriteFullEndElement : unit -> unit
Public Overrides Sub WriteFullEndElement ()

示例

下面的示例写出不包含任何内容的元素。The following example writes out an element with no content. 它使用 WriteFullEndElement 来写入完整的结束元素标记。It uses WriteFullEndElement to write the full end element tag.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   //Create a writer to write XML to the console.
   XmlTextWriter^ writer = nullptr;
   writer = gcnew XmlTextWriter( Console::Out );
   
   //Use indentation for readability.
   writer->Formatting = Formatting::Indented;
   
   //Write an element (this one is the root).
   writer->WriteStartElement( "order" );
   
   //Write some attributes.
   writer->WriteAttributeString( "date", "2/19/01" );
   writer->WriteAttributeString( "orderID", "136A5" );
   
   //Write a full end element. Because this element has no
   //content, calling WriteEndElement would have written a
   //short end tag '/>'.
   writer->WriteFullEndElement();
   
   //Write the XML to file and close the writer
   writer->Close();
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main()
  {
     //Create a writer to write XML to the console.
     XmlTextWriter writer = null;
     writer = new XmlTextWriter (Console.Out);

     //Use indentation for readability.
     writer.Formatting = Formatting.Indented;

     //Write an element (this one is the root).
     writer.WriteStartElement("order");

     //Write some attributes.
     writer.WriteAttributeString("date", "2/19/01");
     writer.WriteAttributeString("orderID", "136A5");

     //Write a full end element. Because this element has no
     //content, calling WriteEndElement would have written a
     //short end tag '/>'.
     writer.WriteFullEndElement();

     //Write the XML to file and close the writer
     writer.Close();
  }
}
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        'Create a writer to write XML to the console.
        Dim writer As XmlTextWriter = Nothing
        writer = New XmlTextWriter(Console.Out)
        
        'Use indentation for readability.
        writer.Formatting = Formatting.Indented
        
        'Write an element (this one is the root).
        writer.WriteStartElement("order")
        
        'Write some attributes.
        writer.WriteAttributeString("date", "2/19/01")
        writer.WriteAttributeString("orderID", "136A5")
        
        'Write a full end element. Because this element has no
        'content, calling WriteEndElement would have written a
        'short end tag '/>'.
        writer.WriteFullEndElement()
        
        'Write the XML to file and close the writer
        writer.Close()
    End Sub
End Class

注解

备注

从 .NET Framework 2.0 开始,我们建议 XmlWriter 使用 XmlWriter.Create 方法和类创建实例, XmlWriterSettings 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlWriter instances by using the XmlWriter.Create method and the XmlWriterSettings class to take advantage of new functionality.

此方法始终写入完整的结束标记。This method always writes the full end tag. 当处理必须包含完整结束标记的元素时,这非常有用。This is useful when dealing with elements that must include a full end tag. 例如,浏览器需要用 "" 关闭 HTML 脚本块 </script> 。For example, browsers expect HTML script blocks to be closed with "</script>".

适用于