我使用的环境是MacOS Sierra上的go1.8。
代码:
package main
import (
"fmt"
"io/ioutil"
"github.com/moovweb/gokogiri"
"github.com/moovweb/gokogiri/xpath"
)
func main() {
fmt.Println("hello world")
b, _ := ioutil.ReadFile("x.xml")
fmt.Println(string(b))
doc, _ := gokogiri.ParseXml(b)
compiled := xpath.Compile("/path/to/node")
ss, _ := doc.Root().Search(compiled)
for _, s := range ss {
fmt.Println(s.Content())
}
}在我构建并运行之后:
$ ./hello-world
Killed: 9即使是hello world消息也没有打印出来。后来,在研究gokogiri自述文件时,我看到了有关安装libxml2的说明。所以我做了brew install libxml2并尝试了,但也没有解决这个问题。
https://stackoverflow.com/questions/44512577
复制相似问题