XmlDocument.CreateTextNode(String) Metódus
Definíció
Fontos
Egyes információk olyan, kiadás előtti termékekre vonatkoznak, amelyek a kiadásig még jelentősen módosulhatnak. A Microsoft nem vállal kifejezett vagy törvényi garanciát az itt megjelenő információért.
Létrehoz egy XmlText adott szöveggel rendelkezőt.
public:
virtual System::Xml::XmlText ^ CreateTextNode(System::String ^ text);
public virtual System.Xml.XmlText CreateTextNode(string text);
public virtual System.Xml.XmlText CreateTextNode(string? text);
abstract member CreateTextNode : string -> System.Xml.XmlText
override this.CreateTextNode : string -> System.Xml.XmlText
Public Overridable Function CreateTextNode (text As String) As XmlText
Paraméterek
- text
- String
A Szöveg csomópont szövege.
Válaszok
Az új csomópont.
Példák
Az alábbi példa létrehoz egy új elemet, és hozzáadja a dokumentumhoz.
using System;
using System.Xml;
public class Sample
{
public static void CreateTextNodeExample()
{
// Create the XmlDocument.
XmlDocument doc = new();
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
"<title>Pride And Prejudice</title>" +
"</book>");
// Create a new node and add it to the document.
// The text node is the content of the price element.
XmlElement elem = doc.CreateElement("price");
XmlText text = doc.CreateTextNode("19.95");
doc.DocumentElement.AppendChild(elem);
doc.DocumentElement.LastChild.AppendChild(text);
Console.WriteLine("Display the modified XML...");
doc.Save(Console.Out);
}
}
Imports System.IO
Imports System.Xml
Public Class Sample
Public Shared Sub Main()
' Create the XmlDocument.
Dim doc As New XmlDocument()
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
"<title>Pride And Prejudice</title>" & _
"</book>")
' Create a new node and add it to the document.
' The text node is the content of the price element.
Dim elem As XmlElement = doc.CreateElement("price")
Dim text As XmlText = doc.CreateTextNode("19.95")
doc.DocumentElement.AppendChild(elem)
doc.DocumentElement.LastChild.AppendChild(text)
Console.WriteLine("Display the modified XML...")
doc.Save(Console.Out)
End Sub
End Class
Megjegyzések
Bár ez a metódus a dokumentum kontextusában hozza létre az új objektumot, nem adja hozzá automatikusan az új objektumot a dokumentumfához. Az új objektum hozzáadásához explicit módon meg kell hívnia a csomópont beszúrási módszereinek egyikét.
A W3C Bővíthető korrektúranyelv (XML) 1.0-s javaslata szerint a szöveges csomópontok csak az elem-, attribútum- és entityreferencia-csomópontokon belül engedélyezettek.