# Selecting a Paragraph using the XmlDocument

Learn how to select a paragraph using the XmlDocument object model available in the C1Editor for WinForms control.

## Content



To perform the same task using the **XmlDocument** object model, you would use this code:

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
void selectXmlNode_Click(object sender, EventArgs e)
{
    // find 6th node in document
    XmlDocument doc = c1Editor1.Document;
    XmlNodeList nodes = SelectNodes(doc, "/html/body/p");
    if (nodes.Count > 5)
    {
        XmlNode node = nodes[5];
        C1TextRange range = c1Editor1.CreateRange();
        range.MoveTo(node);
        range.Select();
    }
}
```

DOC-DETAILS-TAG-CLOSE

The code is considerably simpler. It retrieves the current document from the [C1Editor](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1Editor.html), and then uses the **SelectNodes** helper method to get a list of all paragraph tags. It then creates a [C1TextRange](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1TextRange.html) object, moves this new range to the node that represents the sixth paragraph in the document, and selects the range using the **C1TextRange**'s [Select](/componentone/api/win/online-richtexteditor/dotnet-framework-api/C1.Win.C1Editor.4.8/C1.Win.C1Editor.C1TextRange.Select.html) method.

The **SelectNodes** method is a handy utility that takes care of XML namespaces by automatically creating and using an **XmlNamespaceManager** (this is standard **XmlDocument** logic, not directly related to the C1Editor):

DOC-DETAILS-TAG-OPEN

DOC-SUMMARY-TAG-OPEN

To write code in C#

DOC-SUMMARY-TAG-CLOSE

```csharp
XmlNodeList SelectNodes(XmlDocument doc, string xpath)
{
    if (doc.DocumentElement.Attributes["xmlns"] != null)
    {
        // add namespace manager
        string xmlns = doc.DocumentElement.Attributes["xmlns"].Value;
        XmlNamespaceManager nsmgr = new XmlNamespaceManager(doc.NameTable);
        nsmgr.AddNamespace("x", xmlns);
        xpath = xpath.Replace("/", "/x:");
        return doc.SelectNodes(xpath, nsmgr);
    }
    else
    {
        return doc.SelectNodes(xpath);
    }
}
```

DOC-DETAILS-TAG-CLOSE