本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.Search方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Search方法的具体用法?Golang Node.Search怎么用?Golang Node.Search使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ThomsonReutersEikon/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.Search方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EvalMatch
//.........这里部分代码省略.........
evalFull := true
if context != nil {
prev := m.Steps[i-1]
if prev.Op == OP_PREDICATE {
prev = m.Steps[i-2]
}
if prev.Op == OP_ELEM || prev.Op == OP_ALL {
parent := cur.Parent()
sibs := context.ChildrenOf(parent)
var clen, pos int
for _, n := range sibs {
if n.NodePtr() == cur.NodePtr() {
pos = clen + 1
clen = clen + 1
} else {
if n.NodeType() == xml.XML_ELEMENT_NODE {
if n.Name() == cur.Name() || prev.Op == OP_ALL {
clen = clen + 1
}
}
}
}
if step.Value == "last()" {
if pos != clen {
return false
}
}
//eval predicate should do special number handling
postest, err := strconv.Atoi(step.Value)
if err == nil {
if pos != postest {
return false
}
}
opos, olen := context.XPathContext.GetContextPosition()
context.XPathContext.SetContextPosition(pos, clen)
result := cur.EvalXPathAsBoolean(step.Value, context)
context.XPathContext.SetContextPosition(opos, olen)
if result == false {
return false
}
evalFull = false
}
}
if evalFull {
//if we made it this far, fall back to the more expensive option of evaluating
// the entire pattern globally
//TODO: cache results on first run for given document
xp := m.pattern
if m.pattern[0] != '/' {
xp = "//" + m.pattern
}
e := xpath.Compile(xp)
o, err := node.Search(e)
if err != nil {
//fmt.Println("ERROR",err)
}
for _, n := range o {
if cur.NodePtr() == n.NodePtr() {
return true
}
}
return false
}
case OP_ID:
//TODO: fix lexer to only put literal inside step value
val := strings.Trim(step.Value, "()\"'")
id := cur.MyDocument().NodeById(val)
if id == nil || node.NodePtr() != id.NodePtr() {
return false
}
case OP_KEY:
// TODO: make this robust
if context != nil {
val := strings.Trim(step.Value, "()")
v := strings.Split(val, ",")
keyname := strings.Trim(v[0], "\"'")
keyval := strings.Trim(v[1], "\"'")
key, _ := context.Style.Keys[keyname]
if key != nil {
o, _ := key.nodes[keyval]
for _, n := range o {
if cur.NodePtr() == n.NodePtr() {
return true
}
}
}
}
return false
default:
return false
}
}
//in theory, OP_END means we never reach here
// in practice, we can generate match patterns
// that are missing OP_END due to how we handle OP_OR
return true
}