InnerText和InnerXml的区别
InnerText無格式顯示里面的所有內容,InnerXml含有格式的顯示;應該和InnerText和InnerHtml是一樣的。
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);
?
//來源MSDN
// 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);
Console.Read();
?
輸出:
Display the InnerText of the element...
some textmore text
Display the InnerXml of the element...
some text<child />more text
<elem>Text containing <markup/> will have char(<) and char(>) escape
d.</elem>
<elem>Text containing <markup />.</elem>轉載于:https://www.cnblogs.com/maliya/archive/2010/04/23/1718447.html
總結
以上是生活随笔為你收集整理的InnerText和InnerXml的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 回文数的C语言表述
- 下一篇: OCP之5 管理数据库存储结构