diff --git a/go.mod b/go.mod
index 76b11ce..d0e1216 100644
--- a/go.mod
+++ b/go.mod
@@ -10,7 +10,7 @@ module github.com/atc0005/go-lockss
go 1.20
require (
- github.com/antchfx/xmlquery v1.3.18
+ github.com/antchfx/xmlquery v1.4.0
github.com/apex/log v1.9.0
)
diff --git a/go.sum b/go.sum
index 81c2abc..03cf44b 100644
--- a/go.sum
+++ b/go.sum
@@ -1,6 +1,5 @@
-github.com/antchfx/xmlquery v1.3.18 h1:FSQ3wMuphnPPGJOFhvc+cRQ2CT/rUj4cyQXkJcjOwz0=
-github.com/antchfx/xmlquery v1.3.18/go.mod h1:Afkq4JIeXut75taLSuI31ISJ/zeq+3jG7TunF7noreA=
-github.com/antchfx/xpath v1.2.4/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
+github.com/antchfx/xmlquery v1.4.0 h1:xg2HkfcRK2TeTbdb0m1jxCYnvsPaGY/oeZWTGqX/0hA=
+github.com/antchfx/xmlquery v1.4.0/go.mod h1:Ax2aeaeDjfIw3CwXKDQ0GkwZ6QlxoChlIBP+mGnDFjI=
github.com/antchfx/xpath v1.3.0 h1:nTMlzGAK3IJ0bPpME2urTuFL76o4A96iYvoKFHRXJgc=
github.com/antchfx/xpath v1.3.0/go.mod h1:i54GszH55fYfBmoZXapTHN8T8tkcHfRgLyVwwqzXNcs=
github.com/apex/log v1.9.0 h1:FHtw/xuaM8AgmvDDTI9fiwoAL25Sq2cxojnZICUU8l0=
diff --git a/vendor/github.com/antchfx/xmlquery/.travis.yml b/vendor/github.com/antchfx/xmlquery/.travis.yml
deleted file mode 100644
index 731b767..0000000
--- a/vendor/github.com/antchfx/xmlquery/.travis.yml
+++ /dev/null
@@ -1,17 +0,0 @@
-language: go
-
-go:
- - 1.9.x
- - 1.12.x
- - 1.13.x
- - 1.14.x
- - 1.15.x
-
-install:
- - go get golang.org/x/net/html/charset
- - go get github.com/antchfx/xpath
- - go get github.com/mattn/goveralls
- - go get github.com/golang/groupcache
-
-script:
- - $HOME/gopath/bin/goveralls -service=travis-ci
diff --git a/vendor/github.com/antchfx/xmlquery/README.md b/vendor/github.com/antchfx/xmlquery/README.md
index 11fafde..4d26bfe 100644
--- a/vendor/github.com/antchfx/xmlquery/README.md
+++ b/vendor/github.com/antchfx/xmlquery/README.md
@@ -1,37 +1,33 @@
-xmlquery
-====
-[![Build Status](https://travis-ci.org/antchfx/xmlquery.svg?branch=master)](https://travis-ci.org/antchfx/xmlquery)
-[![Coverage Status](https://coveralls.io/repos/github/antchfx/xmlquery/badge.svg?branch=master)](https://coveralls.io/github/antchfx/xmlquery?branch=master)
+# xmlquery
+
+[![Build Status](https://github.com/antchfx/xmlquery/actions/workflows/testing.yml/badge.svg)](https://github.com/antchfx/xmlquery/actions/workflows/testing.yml)
[![GoDoc](https://godoc.org/github.com/antchfx/xmlquery?status.svg)](https://godoc.org/github.com/antchfx/xmlquery)
[![Go Report Card](https://goreportcard.com/badge/github.com/antchfx/xmlquery)](https://goreportcard.com/report/github.com/antchfx/xmlquery)
-Overview
-===
+# Overview
-`xmlquery` is an XPath query package for XML documents, allowing you to extract
+`xmlquery` is an XPath query package for XML documents, allowing you to extract
data or evaluate from XML documents with an XPath expression.
`xmlquery` has a built-in query object caching feature that caches recently used
-XPATH query strings. Enabling caching can avoid recompile XPath expression for
-each query.
+XPATH query strings. Enabling caching can avoid recompile XPath expression for
+each query.
You can visit this page to learn about the supported XPath(1.0/2.0) syntax. https://github.com/antchfx/xpath
-[htmlquery](https://github.com/antchfx/htmlquery) - Package for the HTML document query.
+[htmlquery](https://github.com/antchfx/htmlquery) - Package for the HTML document query.
+
+[xmlquery](https://github.com/antchfx/xmlquery) - Package for the XML document query.
-[xmlquery](https://github.com/antchfx/xmlquery) - Package for the XML document query.
+[jsonquery](https://github.com/antchfx/jsonquery) - Package for the JSON document query.
-[jsonquery](https://github.com/antchfx/jsonquery) - Package for the JSON document query.
+# Installation
-Installation
-====
```
$ go get github.com/antchfx/xmlquery
```
-
-Quick Starts
-===
+# Quick Starts
```go
import (
@@ -75,8 +71,7 @@ func main(){
}
```
-Getting Started
-===
+# Getting Started
### Find specified XPath query.
@@ -157,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`.
@@ -183,15 +185,21 @@ 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)
```
-Advanced Features
-====
+# Advanced Features
### Parse `UTF-16` XML file with `ParseWithOptions()`.
@@ -273,8 +281,7 @@ Output:
W3Schools Home Page
```
-FAQ
-====
+# FAQ
#### `Find()` vs `QueryAll()`, which is better?
@@ -284,12 +291,12 @@ an error.
#### Can I save my query expression object for the next query?
-Yes, you can. We provide `QuerySelector` and `QuerySelectorAll` methods; they
+Yes, you can. We provide `QuerySelector` and `QuerySelectorAll` methods; they
accept your query expression object.
-Caching a query expression object avoids recompiling the XPath query
+Caching a query expression object avoids recompiling the XPath query
expression, improving query performance.
-Questions
-===
+# Questions
+
Please let me know if you have any questions
diff --git a/vendor/github.com/antchfx/xmlquery/books.xml b/vendor/github.com/antchfx/xmlquery/books.xml
deleted file mode 100644
index 85a74b5..0000000
--- a/vendor/github.com/antchfx/xmlquery/books.xml
+++ /dev/null
@@ -1,121 +0,0 @@
-
-
-
-
- Gambardella, Matthew
- XML Developer's Guide
- Computer
- 44.95
- 2000-10-01
- An in-depth look at creating applications
- with XML.
-
-
- Ralls, Kim
- Midnight Rain
- Fantasy
- 5.95
- 2000-12-16
- A former architect battles corporate zombies,
- an evil sorceress, and her own childhood to become queen
- of the world.
-
-
- Corets, Eva
- Maeve Ascendant
- Fantasy
- 5.95
- 2000-11-17
- After the collapse of a nanotechnology
- society in England, the young survivors lay the
- foundation for a new society.
-
-
- Corets, Eva
- Oberon's Legacy
- Fantasy
- 5.95
- 2001-03-10
- In post-apocalypse England, the mysterious
- agent known only as Oberon helps to create a new life
- for the inhabitants of London. Sequel to Maeve
- Ascendant.
-
-
- Corets, Eva
- The Sundered Grail
- Fantasy
- 5.95
- 2001-09-10
- The two daughters of Maeve, half-sisters,
- battle one another for control of England. Sequel to
- Oberon's Legacy.
-
-
- Randall, Cynthia
- Lover Birds
- Romance
- 4.95
- 2000-09-02
- When Carla meets Paul at an ornithology
- conference, tempers fly as feathers get ruffled.
-
-
- Thurman, Paula
- Splish Splash
- Romance
- 4.95
- 2000-11-02
- A deep sea diver finds true love twenty
- thousand leagues beneath the sea.
-
-
- Knorr, Stefan
- Creepy Crawlies
- Horror
- 4.95
- 2000-12-06
- An anthology of horror stories about roaches,
- centipedes, scorpions and other insects.
-
-
- Kress, Peter
- Paradox Lost
- Science Fiction
- 6.95
- 2000-11-02
- After an inadvertant trip through a Heisenberg
- Uncertainty Device, James Salway discovers the problems
- of being quantum.
-
-
- O'Brien, Tim
- Microsoft .NET: The Programming Bible
- Computer
- 36.95
- 2000-12-09
- Microsoft's .NET initiative is explored in
- detail in this deep programmer's reference.
-
-
- O'Brien, Tim
- MSXML3: A Comprehensive Guide
- Computer
- 36.95
- 2000-12-01
- The Microsoft MSXML3 parser is covered in
- detail, with attention to XML DOM interfaces, XSLT processing,
- SAX and more.
-
-
- Galos, Mike
- Visual Studio 7: A Comprehensive Guide
- Computer
- 49.95
- 2001-04-16
- Microsoft Visual Studio 7 is explored in depth,
- looking at how Visual Basic, Visual C++, C#, and ASP+ are
- integrated into a comprehensive development
- environment.
-
-
\ No newline at end of file
diff --git a/vendor/github.com/antchfx/xmlquery/node.go b/vendor/github.com/antchfx/xmlquery/node.go
index 207892a..28f3f54 100644
--- a/vendor/github.com/antchfx/xmlquery/node.go
+++ b/vendor/github.com/antchfx/xmlquery/node.go
@@ -27,6 +27,8 @@ const (
CommentNode
// AttributeNode is an attribute of element.
AttributeNode
+ // NotationNode is a directive represents in document (for example, ).
+ NotationNode
)
type Attr struct {
@@ -99,6 +101,10 @@ func newXMLName(name string) xml.Name {
}
}
+func (n *Node) Level() int {
+ return n.level
+}
+
// InnerText returns the text between the start and end tags of the object.
func (n *Node) InnerText() string {
var output func(*strings.Builder, *Node)
@@ -153,6 +159,9 @@ func outputXML(b *strings.Builder, n *Node, preserveSpaces bool, config *outputC
b.WriteString("-->")
}
return
+ case NotationNode:
+ fmt.Fprintf(b, "", n.Data)
+ return
case DeclarationNode:
b.WriteString("" + n.Data)
default:
diff --git a/vendor/github.com/antchfx/xmlquery/parse.go b/vendor/github.com/antchfx/xmlquery/parse.go
index fe3de99..daf7233 100644
--- a/vendor/github.com/antchfx/xmlquery/parse.go
+++ b/vendor/github.com/antchfx/xmlquery/parse.go
@@ -8,6 +8,7 @@ import (
"net/http"
"regexp"
"strings"
+ "sync"
"github.com/antchfx/xpath"
"golang.org/x/net/html/charset"
@@ -59,6 +60,13 @@ type parser struct {
streamNode *Node // Need to remember the last target node So we can clean it up upon next Read() call.
streamNodePrev *Node // Need to remember target node's prev so upon target node removal, we can restore correct prev.
reader *cachedReader // Need to maintain a reference to the reader, so we can determine whether a node contains CDATA.
+ once sync.Once
+ space2prefix map[string]*xmlnsPrefix
+}
+
+type xmlnsPrefix struct {
+ name string
+ level int
}
func createParser(r io.Reader) *parser {
@@ -77,9 +85,11 @@ func createParser(r io.Reader) *parser {
}
func (p *parser) parse() (*Node, error) {
- var streamElementNodeCounter int
- space2prefix := map[string]string{"http://www.w3.org/XML/1998/namespace": "xml"}
+ p.once.Do(func() {
+ p.space2prefix = map[string]*xmlnsPrefix{"http://www.w3.org/XML/1998/namespace": {name: "xml", level: 0}}
+ })
+ var streamElementNodeCounter int
for {
p.reader.StartCaching()
tok, err := p.decoder.Token()
@@ -108,16 +118,18 @@ func (p *parser) parse() (*Node, error) {
for _, att := range tok.Attr {
if att.Name.Local == "xmlns" {
- space2prefix[att.Value] = "" // reset empty if exist the default namespace
- // defaultNamespaceURL = att.Value
+ // https://github.com/antchfx/xmlquery/issues/67
+ if prefix, ok := p.space2prefix[att.Value]; !ok || (ok && prefix.level >= p.level) {
+ p.space2prefix[att.Value] = &xmlnsPrefix{name: "", level: p.level} // reset empty if exist the default namespace
+ }
} else if att.Name.Space == "xmlns" {
// maybe there are have duplicate NamespaceURL?
- space2prefix[att.Value] = att.Name.Local
+ p.space2prefix[att.Value] = &xmlnsPrefix{name: att.Name.Local, level: p.level}
}
}
if space := tok.Name.Space; space != "" {
- if _, found := space2prefix[space]; !found && p.decoder.Strict {
+ if _, found := p.space2prefix[space]; !found && p.decoder.Strict {
return nil, fmt.Errorf("xmlquery: invalid XML document, namespace %s is missing", space)
}
}
@@ -125,8 +137,8 @@ func (p *parser) parse() (*Node, error) {
attributes := make([]Attr, len(tok.Attr))
for i, att := range tok.Attr {
name := att.Name
- if prefix, ok := space2prefix[name.Space]; ok {
- name.Space = prefix
+ if prefix, ok := p.space2prefix[name.Space]; ok {
+ name.Space = prefix.name
}
attributes[i] = Attr{
Name: name,
@@ -155,10 +167,10 @@ func (p *parser) parse() (*Node, error) {
}
if node.NamespaceURI != "" {
- if v, ok := space2prefix[node.NamespaceURI]; ok {
+ if v, ok := p.space2prefix[node.NamespaceURI]; ok {
cached := string(p.reader.Cache())
- if strings.HasPrefix(cached, fmt.Sprintf("%s:%s", v, node.Data)) || strings.HasPrefix(cached, fmt.Sprintf("<%s:%s", v, node.Data)) {
- node.Prefix = v
+ if strings.HasPrefix(cached, fmt.Sprintf("%s:%s", v.name, node.Data)) || strings.HasPrefix(cached, fmt.Sprintf("<%s:%s", v.name, node.Data)) {
+ node.Prefix = v.name
}
}
}
@@ -269,6 +281,17 @@ func (p *parser) parse() (*Node, error) {
}
p.prev = node
case xml.Directive:
+ node := &Node{Type: NotationNode, Data: string(tok), level: p.level}
+ if p.level == p.prev.level {
+ AddSibling(p.prev, node)
+ } else if p.level > p.prev.level {
+ AddChild(p.prev, node)
+ } else if p.level < p.prev.level {
+ for i := p.prev.level - p.level; i > 1; i-- {
+ p.prev = p.prev.Parent
+ }
+ AddSibling(p.prev.Parent, node)
+ }
}
}
}
@@ -285,37 +308,43 @@ type StreamParser struct {
// scenarios.
//
// Scenario 1: simple case:
-// xml := `b1b2`
-// sp, err := CreateStreamParser(strings.NewReader(xml), "/AAA/BBB")
-// if err != nil {
-// panic(err)
-// }
-// for {
-// n, err := sp.Read()
-// if err != nil {
-// break
-// }
-// fmt.Println(n.OutputXML(true))
-// }
+//
+// xml := `b1b2`
+// sp, err := CreateStreamParser(strings.NewReader(xml), "/AAA/BBB")
+// if err != nil {
+// panic(err)
+// }
+// for {
+// n, err := sp.Read()
+// if err != nil {
+// break
+// }
+// fmt.Println(n.OutputXML(true))
+// }
+//
// Output will be:
-// b1
-// b2
+//
+// b1
+// b2
//
// Scenario 2: advanced case:
-// xml := `b1b2`
-// sp, err := CreateStreamParser(strings.NewReader(xml), "/AAA/BBB", "/AAA/BBB[. != 'b1']")
-// if err != nil {
-// panic(err)
-// }
-// for {
-// n, err := sp.Read()
-// if err != nil {
-// break
-// }
-// fmt.Println(n.OutputXML(true))
-// }
+//
+// xml := `b1b2`
+// sp, err := CreateStreamParser(strings.NewReader(xml), "/AAA/BBB", "/AAA/BBB[. != 'b1']")
+// if err != nil {
+// panic(err)
+// }
+// for {
+// n, err := sp.Read()
+// if err != nil {
+// break
+// }
+// fmt.Println(n.OutputXML(true))
+// }
+//
// Output will be:
-// b2
+//
+// b2
//
// As the argument names indicate, streamElementXPath should be used for
// providing xpath query pointing to the target element node only, no extra
diff --git a/vendor/github.com/antchfx/xmlquery/query.go b/vendor/github.com/antchfx/xmlquery/query.go
index 9f2493f..d1353aa 100644
--- a/vendor/github.com/antchfx/xmlquery/query.go
+++ b/vendor/github.com/antchfx/xmlquery/query.go
@@ -156,7 +156,7 @@ func (x *NodeNavigator) NodeType() xpath.NodeType {
switch x.curr.Type {
case CommentNode:
return xpath.CommentNode
- case TextNode, CharDataNode:
+ case TextNode, CharDataNode, NotationNode:
return xpath.TextNode
case DeclarationNode, DocumentNode:
return xpath.RootNode
diff --git a/vendor/modules.txt b/vendor/modules.txt
index 97a0e6b..08250d4 100644
--- a/vendor/modules.txt
+++ b/vendor/modules.txt
@@ -1,4 +1,4 @@
-# github.com/antchfx/xmlquery v1.3.18
+# github.com/antchfx/xmlquery v1.4.0
## explicit; go 1.14
github.com/antchfx/xmlquery
# github.com/antchfx/xpath v1.3.0