XmlNode.InnerXml Propriedade
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.
Obtém ou define a marcação que representa apenas os nós filhos deste nó.
public:
virtual property System::String ^ InnerXml { System::String ^ get(); void set(System::String ^ value); };
public virtual string InnerXml { get; set; }
member this.InnerXml : string with get, set
Public Overridable Property InnerXml As String
Valor de Propriedade
A marcação dos nós filhos deste nó, excluindo os atributos padrão.
Exceções
Definir esta propriedade num nó que não pode ter nós filhos.
O XML especificado ao definir esta propriedade não está bem formado.
Exemplos
O exemplo seguinte compara as InnerText propriedades e InnerXml .
using System;
using System.Xml;
public class Test {
public static void Main() {
XmlDocument doc = new XmlDocument();
doc.LoadXml("<root>"+
"<elem>some text<child/>more text</elem>" +
"</root>");
XmlNode elem = doc.DocumentElement.FirstChild;
// Note that InnerText does not include the markup.
Console.WriteLine("Display the InnerText of the element...");
Console.WriteLine( elem.InnerText );
// InnerXml includes the markup of the element.
Console.WriteLine("Display the InnerXml of the element...");
Console.WriteLine(elem.InnerXml);
// Set InnerText to a string that includes markup.
// The markup is escaped.
elem.InnerText = "Text containing <markup/> will have char(<) and char(>) escaped.";
Console.WriteLine( elem.OuterXml );
// Set InnerXml to a string that includes markup.
// The markup is not escaped.
elem.InnerXml = "Text containing <markup/>.";
Console.WriteLine( elem.OuterXml );
}
}
Imports System.Xml
public class Test
public shared sub Main()
Dim doc as XmlDocument = new XmlDocument()
doc.LoadXml("<root>"& _
"<elem>some text<child/>more text</elem>" & _
"</root>")
Dim elem as XmlNode = doc.DocumentElement.FirstChild
' Note that InnerText does not include the markup.
Console.WriteLine("Display the InnerText of the element...")
Console.WriteLine( elem.InnerText )
' InnerXml includes the markup of the element.
Console.WriteLine("Display the InnerXml of the element...")
Console.WriteLine(elem.InnerXml)
' Set InnerText to a string that includes markup.
' The markup is escaped.
elem.InnerText = "Text containing <markup/> will have char(<) and char(>) escaped."
Console.WriteLine( elem.OuterXml )
' Set InnerXml to a string that includes markup.
' The markup is not escaped.
elem.InnerXml = "Text containing <markup/>."
Console.WriteLine( elem.OuterXml )
end sub
end class
Observações
Tentar definir esta propriedade a partir de um nó que não pode ter nós filhos, por exemplo um nó Texto, lança uma exceção. Caso contrário, a definição InnerXml substitui os nós filhos do nó pelo conteúdo analisado da cadeia dada. A análise é feita no contexto de namespace atual.
Esta propriedade é uma extensão da Microsoft para o Modelo de Objetos do Documento (DOM).
Note
InnerXml não é uma forma eficiente de modificar o DOM. Podem existir problemas de desempenho ao substituir nós complexos. É mais eficiente construir nós e usar métodos como InsertBefore, InsertAfter, AppendChild, e RemoveChild modificar o documento Xml.