public CreateDocumentFragment ( ) : |
||
return |
XmlDocumentFragment fragment = doc.CreateDocumentFragment(); fragment.InnerXml = "A Song of Ice and Fire George R.R. Martin "; doc.DocumentElement.AppendChild(fragment);
XmlDocumentFragment fragment = doc.CreateDocumentFragment(); XmlTextWriter writer = new XmlTextWriter(new StringWriter()); writer.WriteStartElement("links"); writer.WriteStartElement("link"); writer.WriteAttributeString("href", "https://www.example.com"); writer.WriteString("Example"); writer.WriteEndElement(); writer.WriteEndElement(); fragment.InnerXml = writer.ToString(); doc.DocumentElement.AppendChild(fragment);This example creates a new XmlDocumentFragment node, creates an XmlTextWriter object to write XML, and sets the InnerXml property of the fragment to the written XML. The resulting XML document will contain a links element with a link child element, including an href attribute and a text value. The System.Xml namespace is a package library that allows for working with XML in .NET applications.