public CreateTextNode ( String text ) : |
||
text | String | |
return |
XmlDocument doc = new XmlDocument(); XmlNode rootNode = doc.CreateElement("root"); doc.AppendChild(rootNode); string text = "Hello World!"; XmlNode textNode = doc.CreateTextNode(text); rootNode.AppendChild(textNode); Console.WriteLine(doc.OuterXml);
XmlDocument doc = new XmlDocument(); doc.LoadXml("In this example, we load an XML document containing three child elements of the root element. We then select all child nodes of the root element using an XPath expression and iterate over them. For each child element, we create a new text node with the string "Some text." and add it as a child node. Finally, we write the entire XML document to the console output. The System.Xml package library in C# is included in the .NET Framework and does not require any additional installation or setup."); XmlNodeList nodeList = doc.SelectNodes("//root/*"); foreach (XmlNode node in nodeList) { string text = "Some text."; XmlNode textNode = doc.CreateTextNode(text); node.AppendChild(textNode); } Console.WriteLine(doc.OuterXml);