Skip to content

Commit e149b6b

Browse files
Snippet2 missing method, generateXMLString (dotnet#8118)
//<Snippet2> is referenced by a documentation page for XmlDocument (see below for URLs). When the code copied from the documentation is pasted into a Windows Forms app and the namespaces added, the code does not compile. The compilation error is caused because one method is missing, generateXMLString. There is a copy button on documentation page which copies <Snippet2>. I moved generateXMLString from the top of xmlhelpermethods.cs where it is not used into //<Snippet2> so it will be included in the example code for the XmlDocument class. //<Snippet2> is referenced by https://docs.microsoft.com/en-us/dotnet/api/system.xml.xmldocument?view=net-6.0 https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System.Xml/XmlDocument.xml Here is where snippet 2 is referenced [!code-csharp[XMLProcessingApp#2](~/snippets/csharp/System.Xml/XmlDocument/Overview/xmlhelpermethods.cs#2)]
1 parent 2e87782 commit e149b6b

File tree

1 file changed

+16
-17
lines changed

1 file changed

+16
-17
lines changed

snippets/csharp/System.Xml/XmlDocument/Overview/xmlhelpermethods.cs

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,24 @@ public XmlDocument LoadDocument(bool generateXML)
4545

4646
//************************************************************************************
4747
//
48-
// Helper method that generates an XML string.
48+
// Loads XML from a file. If the file is not found, load XML from a string.
4949
//
5050
//************************************************************************************
51+
public void SaveXML(XmlDocument doc)
52+
{
53+
doc.Save(Constants.booksFileName);
54+
}
55+
#endregion
56+
57+
#region Validate XML against a Schema
58+
59+
//<Snippet2>
5160

61+
//************************************************************************************
62+
//
63+
// Helper method that generates an XML string.
64+
//
65+
//************************************************************************************
5266
private string generateXMLString()
5367
{
5468
string xml = "<?xml version=\"1.0\"?> \n" +
@@ -68,22 +82,7 @@ private string generateXMLString()
6882
"</books>";
6983
return xml;
7084
}
71-
72-
//************************************************************************************
73-
//
74-
// Loads XML from a file. If the file is not found, load XML from a string.
75-
//
76-
//************************************************************************************
77-
public void SaveXML(XmlDocument doc)
78-
{
79-
doc.Save(Constants.booksFileName);
80-
}
81-
#endregion
82-
83-
#region Validate XML against a Schema
84-
85-
//<Snippet2>
86-
85+
8786
//************************************************************************************
8887
//
8988
// Associate the schema with XML. Then, load the XML and validate it against

0 commit comments

Comments
 (0)