Time for an 2014 update…
This commit is contained in:
parent
372c577f83
commit
09687c4926
2520 changed files with 34227 additions and 7318 deletions
38
Task/XML-XPath/Go/xml-xpath.go
Normal file
38
Task/XML-XPath/Go/xml-xpath.go
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"launchpad.net/xmlpath"
|
||||
)
|
||||
|
||||
func main() {
|
||||
f, err := os.Open("test3.xml")
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
n, err := xmlpath.Parse(f)
|
||||
f.Close()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return
|
||||
}
|
||||
q1 := xmlpath.MustCompile("//item")
|
||||
if _, ok := q1.String(n); !ok {
|
||||
fmt.Println("no item")
|
||||
}
|
||||
q2 := xmlpath.MustCompile("//price")
|
||||
for it := q2.Iter(n); it.Next(); {
|
||||
fmt.Println(it.Node())
|
||||
}
|
||||
q3 := xmlpath.MustCompile("//name")
|
||||
names := []*xmlpath.Node{}
|
||||
for it := q3.Iter(n); it.Next(); {
|
||||
names = append(names, it.Node())
|
||||
}
|
||||
if len(names) == 0 {
|
||||
fmt.Println("no names")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue