Skip to content

Commit

Permalink
update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Apr 2, 2024
1 parent 8b7ab22 commit 25aab14
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ list := xmlquery.Find(doc, "//author")
book := xmlquery.FindOne(doc, "//book[2]")
```

#### Find all book elements and only get `id` attribute. (New Feature)
#### Find the last book.

```go
book := xmlquery.FindOne(doc, "//book[last()]")
```

#### Find all book elements and only get `id` attribute.

```go
list := xmlquery.Find(doc,"//book/@id")
fmt.Println(list[0].InnerText) // outout @id value
```

#### Find all books with id `bk104`.
Expand All @@ -178,10 +185,17 @@ price := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64)
fmt.Printf("total price: %f\n", price)
```

#### Evaluate number of all book elements.
#### Count the number of books.

```go
expr, err := xpath.Compile("count(//book)")
count := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64)
```

#### Calculate the total price of all book prices.

```go
expr, err := xpath.Compile("sum(//book/price)")
price := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64)
```

Expand Down

0 comments on commit 25aab14

Please sign in to comment.