本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.NodePtr方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.NodePtr方法的具体用法?Golang Node.NodePtr怎么用?Golang Node.NodePtr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ThomsonReutersEikon/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.NodePtr方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EvalXPath
func (context *ExecutionContext) EvalXPath(xmlNode xml.Node, data interface{}) (result interface{}, err error) {
switch data := data.(type) {
case string:
if xpathExpr := xpath.Compile(data); xpathExpr != nil {
defer xpathExpr.Free()
result, err = context.EvalXPath(xmlNode, xpathExpr)
} else {
err = errors.New("cannot compile xpath: " + data)
}
case []byte:
result, err = context.EvalXPath(xmlNode, string(data))
case *xpath.Expression:
xpathCtx := context.XPathContext
xpathCtx.SetResolver(context)
err := xpathCtx.Evaluate(xmlNode.NodePtr(), data)
if err != nil {
return nil, err
}
rt := xpathCtx.ReturnType()
switch rt {
case xpath.XPATH_NODESET, xpath.XPATH_XSLT_TREE:
nodePtrs, err := xpathCtx.ResultAsNodeset()
if err != nil {
return nil, err
}
var output []xml.Node
for _, nodePtr := range nodePtrs {
output = append(output, xml.NewNode(nodePtr, xmlNode.MyDocument()))
}
result = output
case xpath.XPATH_NUMBER:
result, err = xpathCtx.ResultAsNumber()
case xpath.XPATH_BOOLEAN:
result, err = xpathCtx.ResultAsBoolean()
default:
result, err = xpathCtx.ResultAsString()
}
default:
err = errors.New("Strange type passed to ExecutionContext.EvalXPath")
}
return
}
示例2: EvalMatch
// Returns true if the node matches the pattern
func (m *CompiledMatch) EvalMatch(node xml.Node, mode string, context *ExecutionContext) bool {
cur := node
//false if wrong mode
// #all is an XSLT 2.0 feature
if m.Template != nil && mode != m.Template.Mode && m.Template.Mode != "#all" {
return false
}
for i, step := range m.Steps {
switch step.Op {
case OP_END:
return true
case OP_ROOT:
if cur.NodeType() != xml.XML_DOCUMENT_NODE {
return false
}
case OP_ELEM:
if cur.NodeType() != xml.XML_ELEMENT_NODE {
return false
}
if step.Value != cur.Name() && step.Value != "*" {
return false
}
case OP_NS:
uri := ""
// m.Template.Node
if m.Template != nil {
uri = context.LookupNamespace(step.Value, m.Template.Node)
} else {
uri = context.LookupNamespace(step.Value, nil)
}
if uri != cur.Namespace() {
return false
}
case OP_ATTR:
if cur.NodeType() != xml.XML_ATTRIBUTE_NODE {
return false
}
if step.Value != cur.Name() && step.Value != "*" {
return false
}
case OP_TEXT:
if cur.NodeType() != xml.XML_TEXT_NODE && cur.NodeType() != xml.XML_CDATA_SECTION_NODE {
return false
}
case OP_COMMENT:
if cur.NodeType() != xml.XML_COMMENT_NODE {
return false
}
case OP_ALL:
if cur.NodeType() != xml.XML_ELEMENT_NODE {
return false
}
case OP_PI:
if cur.NodeType() != xml.XML_PI_NODE {
return false
}
case OP_NODE:
switch cur.NodeType() {
case xml.XML_ELEMENT_NODE, xml.XML_CDATA_SECTION_NODE, xml.XML_TEXT_NODE, xml.XML_COMMENT_NODE, xml.XML_PI_NODE:
// matches any of these node types
default:
return false
}
case OP_PARENT:
cur = cur.Parent()
if cur == nil {
return false
}
case OP_ANCESTOR:
next := m.Steps[i+1]
if next.Op != OP_ELEM {
return false
}
for {
cur = cur.Parent()
if cur == nil {
return false
}
if next.Value == cur.Name() {
break
}
}
case OP_PREDICATE:
// see test REC/5.2-16
// see test REC/5.2-22
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() {
//.........这里部分代码省略.........