Skip to content

Commit c9d8f3f

Browse files
authored
Update query-xpathdocument-xpath-csharp.md
Edit review per CI 6375
1 parent 5db055c commit c9d8f3f

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

support/developer/dotnet/framework/general/query-xpathdocument-xpath-csharp.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
---
2-
title: Query XPathDocument by using an XPath expression
3-
description: Demonstrates how to query an XPathDocument object with an XML Path Language (XPath) expression using the XPathNavigator class.
2+
title: Query XPathDocument By Using an XPath Expression
3+
description: Demonstrates how to query an XPathDocument object by using an XML Path Language (XPath) expression that uses the XPathNavigator class.
44
ms.date: 07/07/2025
55
ms.reviewer: JAYAPST
66
ms.topic: how-to
77
ms.custom: sap:Class Library Namespaces
88

9-
#customer intent: As a developer, I want to query XML documents using XPath expressions so that I can use XML documents with my application.
9+
#customer intent: As a developer, I want to query XML documents by using XPath expressions so that I can use XML documents together with my application.
1010
---
1111
# Query XML with an XPath expression in Visual C\#
1212

13-
This article introduces how to query an `XPathDocument` object with an XML Path Language (XPath) expression by using the `XPathNavigator` class.
13+
This article discusses how to query an `XPathDocument` object by using an XML Path Language (XPath) expression that uses the `XPathNavigator` class.
1414

1515
XPath is used programmatically to evaluate expressions and select specific nodes in a document.
1616

17-
This article refers to the Microsoft .NET Framework Class Library namespace `System.Xml.XPath`.
17+
This article refers to the Microsoft .NET Framework Class Library namespace, `System.Xml.XPath`.
1818

1919
_Applies to:_ Visual Studio, .NET Framework
2020

@@ -29,16 +29,16 @@ This article assumes that you're familiar with the following topics:
2929
- Creating and reading an XML file
3030
- XPath syntax
3131

32-
## Query XPathDocument with an XPath expression
32+
## Query XPathDocument that has an XPath expression
3333

34-
1. Create a new Visual C# Console Application in Visual Studio.
34+
1. In Microsoft Visual Studio, create a Visual C# Console Application.
3535

3636
> [!NOTE]
37-
> This example uses a file named *Books.xml*. You can create your own Books.xml file, or you can use the sample that is included with the .NET Software Development Kit (SDK) quickstarts.
37+
> This example uses a file that's named *Books.xml*. You can create your own Books.xml file, or you can use the sample that's included with the .NET Software Development Kit (SDK) quickstarts.
3838
>
39-
> If you don't have the quickstarts installed and don't want to install them, see the [Related content](#related-content) section for the Books.xml download location.
39+
> If you don't have the quickstarts installed, and you don't want to install them, see the "[Related content](#related-content)" section for the Books.xml download location.
4040
>
41-
> If you have the quickstarts installed, the file can be found in `Program Files\Microsoft.NET\FrameworkSDK\Samples\Quickstart\Howto\Samples\Xml\Transforxml\VB` folder. You can copy the file to the `\Bin\Debug` folder, which is located under the folder in which you created this project.
41+
> If you have the quickstarts installed, the Books.xml file can be found in the `Program Files\Microsoft.NET\FrameworkSDK\Samples\Quickstart\Howto\Samples\Xml\Transforxml\VB` folder. You can copy the file to the `\Bin\Debug` subfolder of the folder in which you created this project.
4242
4343
2. Make sure that the project references the `System.Xml` namespace.
4444
3. Use the `using` statement on the `Xml` and `XPath` namespaces so that you aren't required to qualify declarations in those namespaces later in your code. You can use the `using` statement before any other declarations, as follows:
@@ -48,7 +48,7 @@ This article assumes that you're familiar with the following topics:
4848
using System.Xml.XPath;
4949
```
5050

51-
4. Declare the appropriate variables. Declare an `XPathDocument` object to hold the XML document, an `XpathNavigator` object to evaluate XPath expressions, and an `XPathNodeIterator` object to iterate through selected nodes. Declare a `String` object to hold the XPath expressions. Add the declaration code in the `Main` function in `Class1`.
51+
4. Declare the appropriate variables. Declare an `XPathDocument` object to hold the XML document, an `XpathNavigator` object to evaluate XPath expressions, and an `XPathNodeIterator` object to iterate through selected nodes. Declare a `String` object to hold the XPath expressions. Add the declaration code to the `Main` function in `Class1`.
5252

5353
```csharp
5454
XPathNavigator nav;
@@ -57,21 +57,21 @@ This article assumes that you're familiar with the following topics:
5757
String strExpression;
5858
```
5959

60-
5. Load an `XPathDocument` with the sample file Books.xml. The `XPathDocument` class uses Extensible Stylesheet Language Transformations (XSLT) to provide a fast and performance-oriented cache for XML document processing. It's similar to the XML Document Object Model (DOM) but is highly optimized for XSLT processing and the `XPath` data model.
60+
5. Load an `XPathDocument` together with the sample file, Books.xml. The `XPathDocument` class uses Extensible Stylesheet Language Transformations (XSLT) to provide a fast and performance-oriented cache for XML document processing. It's similar to the XML Document Object Model (DOM) but is highly optimized for XSLT processing and the `XPath` data model.
6161

6262
```csharp
6363
// Open the XML.
6464
docNav = new XPathDocument(@"c:\books.xml");
6565
```
6666

67-
6. Create an `XPathNavigator` from the document. The `XPathNavigator` object is used for read-only XPath queries. The XPath queries may return a resulting value or many nodes.
67+
6. Create an `XPathNavigator` from the document. The `XPathNavigator` object is used for read-only XPath queries. The XPath queries might return a resulting value or many nodes.
6868

6969
```csharp
7070
// Create a navigator to query with XPath.
7171
nav = docNav.CreateNavigator();
7272
```
7373

74-
7. Create an XPath expression to find the average cost of a book. This XPath expression returns a single value. For full details on XPath syntax, see XPath Syntax in the [References](#related-content) section.
74+
7. Create an XPath expression to find the average cost of a book. This XPath expression returns a single value. For full details about XPath syntax, see **XPath Syntax** in the "[References](#related-content)" section.
7575

7676
```csharp
7777
// Find the average cost of a book.
@@ -86,21 +86,21 @@ This article assumes that you're familiar with the following topics:
8686
Console.WriteLine("The average cost of the books are {0}", nav.Evaluate(strExpression));
8787
```
8888

89-
9. Create an XPath expression to find all of the books that cost more than 10 dollars. This XPath expression returns only Title nodes from the XML source.
89+
9. Create an XPath expression to find all the books that cost more than 10 dollars. This XPath expression returns only Title nodes from the XML source.
9090

9191
```csharp
9292
// Find the title of the books that are greater then $10.00.
9393
strExpression = "/bookstore/book/title[../price>10.00]";
9494
```
9595

96-
10. Create an `XPathNodeIterator` for the nodes that are selected with the `Select` method of the `XPathNavigator`. The `XPathNodeIterator` represents an XPath nodeset, and supports operations on this nodeset.
96+
10. Create an `XPathNodeIterator` for the nodes that are selected together with the `Select` method of the `XPathNavigator`. The `XPathNodeIterator` represents an XPath nodeset, and supports operations on this nodeset.
9797

9898
```csharp
9999
// Select the node and place the results in an iterator.
100100
NodeIter = nav.Select(strExpression);
101101
```
102102

103-
11. Use the `XPathNodeIterator`, which was returned from the `Select` method of `XPathNavigator`, to move through the selected nodes. In this case, you can use the `MoveNext` method of the `XPathNodeIterator` to iterate through all of the selected nodes.
103+
11. To move through the selected nodes, use the `XPathNodeIterator` that was returned from the `Select` method of `XPathNavigator`. In this case, you can use the `MoveNext` method of the `XPathNodeIterator` to iterate through all the selected nodes.
104104

105105
```csharp
106106
Console.WriteLine("List of expensive books:");
@@ -111,7 +111,7 @@ This article assumes that you're familiar with the following topics:
111111
};
112112
```
113113

114-
12. Use the `ReadLine` method to add a pause at the end of the console display to more readily display the above results.
114+
12. Use the `ReadLine` method to add a pause at the end of the console display to more readily display the results from the previous steps.
115115

116116
```csharp
117117
// Pause
@@ -125,20 +125,20 @@ This article assumes that you're familiar with the following topics:
125125

126126
### Troubleshooting
127127

128-
When you test the code, you may receive the following exception error message:
128+
When you test the code, you might receive the following exception error message:
129129

130130
```console
131131
An unhandled exception of type System.Xml.XmlException occurred in System.xml.dll
132132
Additional information: System error.
133133
```
134134

135-
The exception error occurs on the following line of code:
135+
This exception occurs on the following line of code:
136136

137137
```csharp
138138
docNav = new XPathDocument("c:\\books.xml");
139139
```
140140

141-
The exception error is caused by an invalid processing instruction. For example, the processing instruction may contain extraneous spaces. The following example is an invalid processing instruction:
141+
The error is caused by an invalid processing instruction. For example, the processing instruction might contain extraneous spaces. The following example is an invalid processing instruction:
142142

143143
```xml
144144
<?xml version='1.0' ?>

0 commit comments

Comments
 (0)