Skip to content

Commit 292b0be

Browse files
committed
fix it properly
1 parent e4e1a0d commit 292b0be

File tree

5 files changed

+37
-37
lines changed

5 files changed

+37
-37
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Library</OutputType>
5+
<TargetFramework>net9.0</TargetFramework>
6+
</PropertyGroup>
7+
8+
</Project>
Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
// <Snippet1>
22
using System;
3-
using System.IO;
43
using System.Xml;
54

65
public class Sample
76
{
8-
public static void Main()
7+
public static void CreateTextNodeExample()
98
{
10-
//Create the XmlDocument.
11-
XmlDocument doc = new XmlDocument();
9+
// Create the XmlDocument.
10+
XmlDocument doc = new();
1211
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" +
1312
"<title>Pride And Prejudice</title>" +
1413
"</book>");
1514

16-
//Create a new node and add it to the document.
17-
//The text node is the content of the price element.
15+
// Create a new node and add it to the document.
16+
// The text node is the content of the price element.
1817
XmlElement elem = doc.CreateElement("price");
1918
XmlText text = doc.CreateTextNode("19.95");
2019
doc.DocumentElement.AppendChild(elem);
@@ -24,14 +23,4 @@ public static void Main()
2423
doc.Save(Console.Out);
2524
}
2625
}
27-
/*
28-
The example displays the following output:
29-
30-
Display the modified XML...
31-
<?xml version="1.0" encoding="us-ascii"?>
32-
<book genre="novel" ISBN="1-861001-57-5">
33-
<title>Pride And Prejudice</title>
34-
<price>19.95</price>
35-
</book>
36-
*/
37-
// </Snippet1>
26+
// </Snippet1>

snippets/csharp/System.Xml/XmlDocument/CreateElement/source1.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
using System.IO;
44
using System.Xml;
55

6-
public class Sample {
7-
8-
public static void Main() {
9-
6+
public class Sample1
7+
{
8+
public static void CreateElementExample()
9+
{
1010
// Create the XmlDocument.
11-
XmlDocument doc = new XmlDocument();
11+
XmlDocument doc = new();
1212
string xmlData = "<book xmlns:bk='urn:samples'></book>";
1313

1414
doc.Load(new StringReader(xmlData));
@@ -22,4 +22,4 @@ public static void Main() {
2222
doc.Save(Console.Out);
2323
}
2424
}
25-
// </Snippet1>
25+
// </Snippet1>

snippets/visualbasic/VS_Snippets_Data/Classic WebData XmlDocument.CreateElement Example/VB/source.vb

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Imports System.Xml
66

77
Public Class Sample
88
Public Shared Sub Main()
9-
9+
1010
' Create the XmlDocument.
1111
Dim doc As New XmlDocument()
1212
doc.LoadXml("<book genre='novel' ISBN='1-861001-57-5'>" & _
@@ -22,17 +22,7 @@ Public Class Sample
2222

2323
Console.WriteLine("Display the modified XML...")
2424
doc.Save(Console.Out)
25-
26-
End Sub
27-
End Class
28-
29-
' The example displays the following output:
30-
'
31-
' Display the modified XML...
32-
' <?xml version="1.0" encoding="utf-8"?>
33-
' <book genre="novel" ISBN="1-861001-57-5">
34-
' <title>Pride And Prejudice</title>
35-
' <price>19.95</price>
36-
' \</book>
3725

26+
End Sub
27+
End Class
3828
' </Snippet1>

xml/System.Xml/XmlDocument.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,19 @@ The following example creates a new element and adds it to the document.
10291029
[!code-csharp[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/csharp/System.Xml/XmlDocument/CreateElement/source.cs#1)]
10301030
[!code-vb[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/visualbasic/VS_Snippets_Data/Classic WebData XmlDocument.CreateElement Example/VB/source.vb#1)]
10311031
1032+
The example produces the following output:
1033+
1034+
```output
1035+
' The example displays the following output:
1036+
'
1037+
' Display the modified XML...
1038+
' <?xml version="1.0" encoding="utf-8"?>
1039+
' <book genre="novel" ISBN="1-861001-57-5">
1040+
' <title>Pride And Prejudice</title>
1041+
' <price>19.95</price>
1042+
' </book>
1043+
```
1044+
10321045
]]></format>
10331046
</remarks>
10341047
</Docs>
@@ -1991,7 +2004,7 @@ The following example adds significant white space to the document.
19912004
<format type="text/markdown"><![CDATA[
19922005
19932006
## Remarks
1994-
2007+
19952008
Although this method creates the new object in the context of the document, it does not automatically add the new object to the document tree. To add the new object, you must explicitly call one of the node insert methods.
19962009
19972010
According to the W3C [Extensible Markup Language (XML) 1.0 recommendation](https://www.w3.org/TR/1998/REC-xml-19980210), Text nodes are only allowed within Element, Attribute and EntityReference nodes.

0 commit comments

Comments
 (0)