Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Library</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

</Project>
23 changes: 6 additions & 17 deletions snippets/csharp/System.Xml/XmlDocument/CreateElement/source.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
// <Snippet1>
using System;
using System.IO;
using System.Xml;

public class Sample
{
public static void Main()
public static void CreateTextNodeExample()
{
//Create the XmlDocument.
XmlDocument doc = new XmlDocument();
// 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.
// 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);
Expand All @@ -24,14 +23,4 @@ public static void Main()
doc.Save(Console.Out);
}
}
/*
The example displays the following output:

Display the modified XML...
<?xml version="1.0" encoding="us-ascii"?>
<book genre="novel" ISBN="1-861001-57-5">
<title>Pride And Prejudice</title>
<price>19.95</price>
</book>
*/
// </Snippet1>
// </Snippet1>
12 changes: 6 additions & 6 deletions snippets/csharp/System.Xml/XmlDocument/CreateElement/source1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
using System.IO;
using System.Xml;

public class Sample {

public static void Main() {

public class Sample1
{
public static void CreateElementExample()
{
// Create the XmlDocument.
XmlDocument doc = new XmlDocument();
XmlDocument doc = new();
string xmlData = "<book xmlns:bk='urn:samples'></book>";

doc.Load(new StringReader(xmlData));
Expand All @@ -22,4 +22,4 @@ public static void Main() {
doc.Save(Console.Out);
}
}
// </Snippet1>
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -1,36 +1,28 @@
' <Snippet1>
Option Explicit
Option Strict

' <Snippet1>
Imports System.IO
Imports System.Xml

Public Class Sample

Public Shared Sub Main()
'Create the XmlDocument.

' 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.
' 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
' The example displays the following output:
'
' Display the modified XML...
' <?xml version="1.0" encoding="utf-8"?>
' <book genre="novel" ISBN="1-861001-57-5">
' <title>Pride And Prejudice</title>
' <price>19.95</price>
' </book>
' </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -51,25 +51,23 @@

The following table shows an example of how the <xref:System.Windows.Forms.ListView.ListViewItemCollection> stores the items of the <xref:System.Windows.Forms.ListView> as well as their selection states in an example <xref:System.Windows.Forms.ListView> control.

|Index|Item|Selection state in the ListView|
|-----------|----------|-------------------------------------|
|0|Item1|Unselected|
|1|Item2|Selected|
|2|Item3|Unselected|
|3|Item4|Selected|
|4|Item5|Selected|
| Index | Item | Selection state in the ListView |
|-------|-------|---------------------------------|
| 0 | Item1 | Unselected |
| 1 | Item2 | Selected |
| 2 | Item3 | Unselected |
| 3 | Item4 | Selected |
| 4 | Item5 | Selected |

Based on the <xref:System.Windows.Forms.ListView.ListViewItemCollection> example in the previous table, the following table demonstrates how the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection> would appear.

|Index|Selected item in the ListViewItemCollection|
|-----------|-------------------------------------------------|
|0|Item2|
|1|Item4|
|2|Item5|
| Index | Selected item in the ListViewItemCollection |
|-------|---------------------------------------------|
| 0 | Item2 |
| 1 | Item4 |
| 2 | Item5 |

You can use the properties and methods of this class to perform a variety of tasks with the collection. The <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection.Contains%2A> method enables you to determine whether an item from the <xref:System.Windows.Forms.ListView.ListViewItemCollection> class is a member of the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection>. Once you know that the item is in the collection, you can use the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection.IndexOf%2A> method to determine the position of the item in the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection>.


You can use the properties and methods of this class to perform a variety of tasks with the collection. The <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection.Contains%2A> method enables you to determine whether an item from the <xref:System.Windows.Forms.ListView.ListViewItemCollection> class is a member of the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection>. Once you know that the item is in the collection, you can use the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection.IndexOf%2A> method to determine the position of the item in the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection>.

## Examples
The following code example demonstrates using the <xref:System.Windows.Forms.ListView.SelectedItems%2A>, <xref:System.Windows.Forms.ListView.SelectedIndexChanged> event, and <xref:System.Windows.Forms.ListView.HeaderStyle%2A> members and the <xref:System.Windows.Forms.ListView.SelectedListViewItemCollection> class. To run this example, paste the following code in a form that contains a <xref:System.Windows.Forms.ListView> object named `ListView1` and a <xref:System.Windows.Forms.TextBox> named `TextBox1`. Call the `InitializeListView` method from the form's constructor or the <xref:System.Windows.Forms.Form.Load> event handler. This example requires that the event handler is correctly associated with the <xref:System.Windows.Forms.ListView.SelectedIndexChanged> event
Expand Down Expand Up @@ -149,15 +147,8 @@
</ReturnValue>
<Parameters />
<Docs>
<summary>Removes all items from the collection.</summary>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks
This method enables you to clear all selections from the <xref:System.Windows.Forms.ListView> control.

]]></format>
</remarks>
<summary>Clears all selections in the list view.</summary>
<remarks>To be added.</remarks>
</Docs>
</Member>
<Member MemberName="Contains">
Expand Down Expand Up @@ -187,7 +178,7 @@
<Parameter Name="item" Type="System.Windows.Forms.ListViewItem" />
</Parameters>
<Docs>
<param name="item">A <see cref="T:System.Windows.Forms.ListViewItem" /> representing the item to locate in the collection.</param>
<param name="item">The item to locate in the collection.</param>
<summary>Determines whether the specified item is located in the collection.</summary>
<returns>
<see langword="true" /> if the specified item is located in the collection; otherwise, <see langword="false" />.</returns>
Expand Down Expand Up @@ -231,7 +222,7 @@
<param name="key">The name of the item to find in the collection.</param>
<summary>Determines whether an item with the specified key is contained in the collection.</summary>
<returns>
<see langword="true" /> to indicate the specified item is contained in the collection; otherwise, <see langword="false" />.</returns>
<see langword="true" /> if the specified item is contained in the collection; otherwise, <see langword="false" />.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

Expand Down Expand Up @@ -275,7 +266,7 @@
<Parameter Name="index" Type="System.Int32" />
</Parameters>
<Docs>
<param name="dest">An <see cref="T:System.Array" /> representing the array to copy the contents of the collection to.</param>
<param name="dest">The array to copy the contents of the collection to.</param>
<param name="index">The location within the destination array to copy the items from the collection to.</param>
<summary>Copies the entire collection into an existing array at a specified location within the array.</summary>
<remarks>
Expand Down Expand Up @@ -393,9 +384,9 @@
<Parameter Name="item" Type="System.Windows.Forms.ListViewItem" />
</Parameters>
<Docs>
<param name="item">A <see cref="T:System.Windows.Forms.ListViewItem" /> representing the item to locate in the collection.</param>
<param name="item">The item to locate in the collection.</param>
<summary>Returns the index within the collection of the specified item.</summary>
<returns>The zero-based index of the item in the collection. If the item is not located in the collection, the return value is negative one (-1).</returns>
<returns>The zero-based index of the item in the collection. If the item is not located in the collection, returns -1.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

Expand Down Expand Up @@ -783,7 +774,7 @@ This member is an explicit interface member implementation. It can be used only
<Parameter Name="item" Type="System.Object" />
</Parameters>
<Docs>
<param name="item">An object that represents the item to locate in the collection.</param>
<param name="item">The item to locate in the collection.</param>
<summary>Returns the index, within the collection, of the specified item.</summary>
<returns>The zero-based index of the item if it is in the collection; otherwise, -1</returns>
<remarks>To be added.</remarks>
Expand Down
2 changes: 2 additions & 0 deletions xml/System.Xml/XmlDictionaryWriter.xml
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@
<Docs>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
<inheritdoc />
</Docs>
</Member>
<MemberGroup MemberName="CreateBinaryWriter">
Expand Down Expand Up @@ -838,6 +839,7 @@ binarywriter.WriteEndAttribute();
<param name="disposing">To be added.</param>
<summary>To be added.</summary>
<remarks>To be added.</remarks>
<inheritdoc />
</Docs>
</Member>
<Member MemberName="EndCanonicalization">
Expand Down
22 changes: 17 additions & 5 deletions xml/System.Xml/XmlDocument.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,17 @@ The following example creates a new element and adds it to the document.
[!code-csharp[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/csharp/System.Xml/XmlDocument/CreateElement/source.cs#1)]
[!code-vb[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/visualbasic/VS_Snippets_Data/Classic WebData XmlDocument.CreateElement Example/VB/source.vb#1)]

The example produces the following output:

```output
Display the modified XML...
<?xml version="1.0" encoding="utf-8"?>
<book genre="novel" ISBN="1-861001-57-5">
<title>Pride And Prejudice</title>
<price>19.95</price>
</book>
```

]]></format>
</remarks>
</Docs>
Expand Down Expand Up @@ -1986,21 +1997,22 @@ The following example adds significant white space to the document.
<Docs>
<param name="text">The text for the Text node.</param>
<summary>Creates an <see cref="T:System.Xml.XmlText" /> with the specified text.</summary>
<returns>The new <see langword="XmlText" /> node.</returns>
<returns>The new node.</returns>
<remarks>
<format type="text/markdown"><![CDATA[

## Remarks
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.

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.
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.

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.

## Examples

The following example creates a new element and adds it to the document.

[!code-csharp[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/csharp/System.Xml/XmlDocument/CreateElement/source.cs#1)]
[!code-vb[Classic WebData XmlDocument.CreateElement Example#1](~/snippets/visualbasic/VS_Snippets_Data/Classic WebData XmlDocument.CreateElement Example/VB/source.vb#1)]
:::code language="csharp" source="~/snippets/csharp/System.Xml/XmlDocument/CreateElement/source.cs" id="Snippet1":::
:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Data/Classic WebData XmlDocument.CreateElement Example/VB/source.vb" id="Snippet1":::

]]></format>
</remarks>
Expand Down