XmlDocument.CreateWhitespace(String) Método
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Cria um XmlWhitespace nó.
public:
virtual System::Xml::XmlWhitespace ^ CreateWhitespace(System::String ^ text);
public virtual System.Xml.XmlWhitespace CreateWhitespace(string text);
abstract member CreateWhitespace : string -> System.Xml.XmlWhitespace
override this.CreateWhitespace : string -> System.Xml.XmlWhitespace
Public Overridable Function CreateWhitespace (text As String) As XmlWhitespace
Parâmetros
- text
- String
A cadeia deve conter apenas os seguintes caracteres e .
Devoluções
Um novo XmlWhitespace nó.
Exemplos
O exemplo seguinte adiciona espaço em branco ao documento.
using System;
using System.Xml;
public class Sample {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<author>" +
"<first-name>Eva</first-name>"+
"<last-name>Corets</last-name>" +
"</author>");
Console.WriteLine("InnerText before...");
Console.WriteLine(doc.DocumentElement.InnerText);
// Add white space.
XmlNode currNode=doc.DocumentElement;
XmlWhitespace ws = doc.CreateWhitespace("\r\n");
currNode.InsertAfter(ws, currNode.FirstChild);
Console.WriteLine();
Console.WriteLine("InnerText after...");
Console.WriteLine(doc.DocumentElement.InnerText);
}
}
Option Explicit
Option Strict
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
Dim doc As New XmlDocument()
doc.LoadXml("<author>" & _
"<first-name>Eva</first-name>" & _
"<last-name>Corets</last-name>" & _
"</author>")
Console.WriteLine("InnerText before...")
Console.WriteLine(doc.DocumentElement.InnerText)
' Add white space.
Dim currNode as XmlNode = doc.DocumentElement
Dim ws As XmlWhitespace = doc.CreateWhitespace(ControlChars.CrLf)
currNode.InsertAfter(ws, currNode.FirstChild)
Console.WriteLine()
Console.WriteLine("InnerText after...")
Console.WriteLine(doc.DocumentElement.InnerText)
End Sub
End Class
Observações
Este método é uma extensão da Microsoft para o Document Object Model (DOM). É usado quando quer formatar manualmente o seu documento.
Embora este método crie o novo objeto no contexto do documento, não adiciona automaticamente o novo objeto à árvore do documento. Para adicionar o novo objeto, deve chamar explicitamente um dos métodos de inserção de nó.