Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Xpath in c #

Shulou Source: shulou.com Published: 2022-06-03 11:55:23 10月01日 Update

Editor to share with you how to use Xpath in c #, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's learn about it!

In c #, we often find and traverse nodes, which is the XPath syntax we can use. XPath syntax is very simple, but powerful enough. XPath can quickly locate nodes or attributes in Xml. It is also the basic knowledge of using xslt.

Example Xml:

100 this is a black cat 80 this is a white cat 80 this is a yellow cat 100 this is a black dog 80 this is a white dog 80 this is a yellow dog

The syntax of XPath:

1. Symbols in XPath

Symbol

Description

Example

Example illustration

/

Indicates that the selection starts from the root node

/ pets

Select the root node pets

Represents the spacer between a node and a child node

/ pets/dog

Select the dog node under the pets node

/ / xx

Means to look from the entire xml document, regardless of the current node location

/ / price

Select all price nodes in the document

.

A single English half-corner period indicates the selection of the current node

/ pets/.

Select the pets node

..

Double dots, indicating that the parent node is selected

/ pets/dog [0] /..

Represents the pets node, which is the parent of the first dog node

@ xx

Represents a selection attribute

/ / dog/@color

Represents a collection of color attributes for selecting all dog nodes

[.]

The square bracket indicates the selection condition, and the condition is in the bracket.

/ / dog [@ color='white']

All dog nodes whose color is white

/ / dog [/ price is greater than

> = greater than or equal to

< less than

Tags: Nodes selections attributes functions names examples casks documents grammars descendants keywords keywords animals bytes numbers conditions articles operations between code Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information NVidia Xiaomi Linux macOS