pax_global_header 0000666 0000000 0000000 00000000064 13736610474 0014525 g ustar 00root root 0000000 0000000 52 comment=5e9685f9dbf17c161d463189a0a5e6c99938bba0
xmlquery-1.3.3/ 0000775 0000000 0000000 00000000000 13736610474 0013417 5 ustar 00root root 0000000 0000000 xmlquery-1.3.3/.gitignore 0000664 0000000 0000000 00000000462 13736610474 0015411 0 ustar 00root root 0000000 0000000 # vscode
.vscode
debug
*.test
./build
# Compiled Object files, Static and Dynamic libs (Shared Objects)
*.o
*.a
*.so
# Folders
_obj
_test
# Architecture specific extensions/prefixes
*.[568vq]
[568vq].out
*.cgo1.go
*.cgo2.c
_cgo_defun.c
_cgo_gotypes.go
_cgo_export.*
_testmain.go
*.exe
*.test
*.prof xmlquery-1.3.3/.travis.yml 0000664 0000000 0000000 00000000450 13736610474 0015527 0 ustar 00root root 0000000 0000000 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
xmlquery-1.3.3/LICENSE 0000664 0000000 0000000 00000001776 13736610474 0014437 0 ustar 00root root 0000000 0000000 Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE. xmlquery-1.3.3/README.md 0000664 0000000 0000000 00000014672 13736610474 0014710 0 ustar 00root root 0000000 0000000 xmlquery
====
[](https://travis-ci.org/antchfx/xmlquery)
[](https://coveralls.io/github/antchfx/xmlquery?branch=master)
[](https://godoc.org/github.com/antchfx/xmlquery)
[](https://goreportcard.com/report/github.com/antchfx/xmlquery)
Overview
===
`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.
Change Logs
===
2020-08-??
- Add XML stream loading and parsing support.
2019-11-11
- Add XPath query caching.
2019-10-05
- Add new methods compatible with invalid XPath expression error: `QueryAll` and `Query`.
- Add `QuerySelector` and `QuerySelectorAll` methods, support for reused query objects.
- PR [#12](https://github.com/antchfx/xmlquery/pull/12) (Thanks @FrancescoIlario)
- PR [#11](https://github.com/antchfx/xmlquery/pull/11) (Thanks @gjvnq)
2018-12-23
- Added XML output including comment nodes. [#9](https://github.com/antchfx/xmlquery/issues/9)
2018-12-03
- Added support to attribute name with namespace prefix and XML output. [#6](https://github.com/antchfx/xmlquery/issues/6)
Installation
====
```
$ go get github.com/antchfx/xmlquery
```
Getting Started
===
### Find specified XPath query.
```go
list, err := xmlquery.QueryAll(doc, "a")
if err != nil {
panic(err)
}
```
#### Parse an XML from URL.
```go
doc, err := xmlquery.LoadURL("http://www.example.com/sitemap.xml")
```
#### Parse an XML from string.
```go
s := ``
doc, err := xmlquery.Parse(strings.NewReader(s))
```
#### Parse an XML from io.Reader.
```go
f, err := os.Open("../books.xml")
doc, err := xmlquery.Parse(f)
```
#### Parse an XML in a stream fashion (simple case without elements filtering).
```go
f, err := os.Open("../books.xml")
p, err := xmlquery.CreateStreamParser(f, "/bookstore/book")
for {
n, err := p.Read()
if err == io.EOF {
break
}
if err != nil {
...
}
}
```
#### Parse an XML in a stream fashion (simple case advanced element filtering).
```go
f, err := os.Open("../books.xml")
p, err := xmlquery.CreateStreamParser(f, "/bookstore/book", "/bookstore/book[price>=10]")
for {
n, err := p.Read()
if err == io.EOF {
break
}
if err != nil {
...
}
}
```
#### Find authors of all books in the bookstore.
```go
list := xmlquery.Find(doc, "//book//author")
// or
list := xmlquery.Find(doc, "//author")
```
#### Find the second book.
```go
book := xmlquery.FindOne(doc, "//book[2]")
```
#### Find all book elements and only get `id` attribute. (New Feature)
```go
list := xmlquery.Find(doc,"//book/@id")
```
#### Find all books with id `bk104`.
```go
list := xmlquery.Find(doc, "//book[@id='bk104']")
```
#### Find all books with price less than 5.
```go
list := xmlquery.Find(doc, "//book[price<5]")
```
#### Evaluate total price of all books.
```go
expr, err := xpath.Compile("sum(//book/price)")
price := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64)
fmt.Printf("total price: %f\n", price)
```
#### Evaluate number of all book elements.
```go
expr, err := xpath.Compile("count(//book)")
price := expr.Evaluate(xmlquery.CreateXPathNavigator(doc)).(float64)
```
FAQ
====
#### `Find()` vs `QueryAll()`, which is better?
`Find` and `QueryAll` both do the same thing: searches all of matched XML nodes.
`Find` panics if provided with an invalid XPath query, while `QueryAll` returns
an error.
#### Can I save my query expression object for the next query?
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
expression, improving query performance.
#### Create XML document.
```go
doc := &xmlquery.Node{
Type: xmlquery.DeclarationNode,
Data: "xml",
Attr: []xml.Attr{
xml.Attr{Name: xml.Name{Local: "version"}, Value: "1.0"},
},
}
root := &xmlquery.Node{
Data: "rss",
Type: xmlquery.ElementNode,
}
doc.FirstChild = root
channel := &xmlquery.Node{
Data: "channel",
Type: xmlquery.ElementNode,
}
root.FirstChild = channel
title := &xmlquery.Node{
Data: "title",
Type: xmlquery.ElementNode,
}
title_text := &xmlquery.Node{
Data: "W3Schools Home Page",
Type: xmlquery.TextNode,
}
title.FirstChild = title_text
channel.FirstChild = title
fmt.Println(doc.OutputXML(true))
// W3Schools Home Page
```
Quick Tutorial
===
```go
import (
"github.com/antchfx/xmlquery"
)
func main(){
s := `
W3Schools Home Page
https://www.w3schools.com
Free web building tutorialsRSS Tutorial
https://www.w3schools.com/xml/xml_rss.asp
New RSS tutorial on W3SchoolsXML Tutorial
https://www.w3schools.com/xml
New XML tutorial on W3Schools`
doc, err := xmlquery.Parse(strings.NewReader(s))
if err != nil {
panic(err)
}
channel := xmlquery.FindOne(doc, "//channel")
if n := channel.SelectElement("title"); n != nil {
fmt.Printf("title: %s\n", n.InnerText())
}
if n := channel.SelectElement("link"); n != nil {
fmt.Printf("link: %s\n", n.InnerText())
}
for i, n := range xmlquery.Find(doc, "//item/title") {
fmt.Printf("#%d %s\n", i, n.InnerText())
}
}
```
List of supported XPath query packages
===
| Name | Description |
| ------------------------------------------------- | ----------------------------------------- |
| [htmlquery](https://github.com/antchfx/htmlquery) | XPath query package for HTML documents |
| [xmlquery](https://github.com/antchfx/xmlquery) | XPath query package for XML documents |
| [jsonquery](https://github.com/antchfx/jsonquery) | XPath query package for JSON documents |
Questions
===
Please let me know if you have any questions
xmlquery-1.3.3/books.xml 0000664 0000000 0000000 00000010607 13736610474 0015262 0 ustar 00root root 0000000 0000000
Gambardella, MatthewXML Developer's GuideComputer44.952000-10-01An in-depth look at creating applications
with XML.Ralls, KimMidnight RainFantasy5.952000-12-16A former architect battles corporate zombies,
an evil sorceress, and her own childhood to become queen
of the world.Corets, EvaMaeve AscendantFantasy5.952000-11-17After the collapse of a nanotechnology
society in England, the young survivors lay the
foundation for a new society.Corets, EvaOberon's LegacyFantasy5.952001-03-10In 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, EvaThe Sundered GrailFantasy5.952001-09-10The two daughters of Maeve, half-sisters,
battle one another for control of England. Sequel to
Oberon's Legacy.Randall, CynthiaLover BirdsRomance4.952000-09-02When Carla meets Paul at an ornithology
conference, tempers fly as feathers get ruffled.Thurman, PaulaSplish SplashRomance4.952000-11-02A deep sea diver finds true love twenty
thousand leagues beneath the sea.Knorr, StefanCreepy CrawliesHorror4.952000-12-06An anthology of horror stories about roaches,
centipedes, scorpions and other insects.Kress, PeterParadox LostScience Fiction6.952000-11-02After an inadvertant trip through a Heisenberg
Uncertainty Device, James Salway discovers the problems
of being quantum.O'Brien, TimMicrosoft .NET: The Programming BibleComputer36.952000-12-09Microsoft's .NET initiative is explored in
detail in this deep programmer's reference.O'Brien, TimMSXML3: A Comprehensive GuideComputer36.952000-12-01The Microsoft MSXML3 parser is covered in
detail, with attention to XML DOM interfaces, XSLT processing,
SAX and more.Galos, MikeVisual Studio 7: A Comprehensive GuideComputer49.952001-04-16Microsoft Visual Studio 7 is explored in depth,
looking at how Visual Basic, Visual C++, C#, and ASP+ are
integrated into a comprehensive development
environment.