本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.Attributes方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.Attributes方法的具体用法?Golang Node.Attributes怎么用?Golang Node.Attributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/ThomsonReutersEikon/gokogiri/xml.Node
的用法示例。
在下文中一共展示了Node.Attributes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: copyToOutput
func (i *XsltInstruction) copyToOutput(node xml.Node, context *ExecutionContext, recursive bool) {
switch node.NodeType() {
case xml.XML_TEXT_NODE:
if context.UseCDataSection(context.OutputNode) {
r := context.Output.CreateCDataNode(node.Content())
context.OutputNode.AddChild(r)
} else {
r := context.Output.CreateTextNode(node.Content())
context.OutputNode.AddChild(r)
}
case xml.XML_ATTRIBUTE_NODE:
aname := node.Name()
ahref := node.Namespace()
val := node.Content()
if ahref == "" {
context.OutputNode.SetAttr(aname, val)
} else {
context.OutputNode.SetNsAttr(ahref, aname, val)
}
case xml.XML_COMMENT_NODE:
r := context.Output.CreateCommentNode(node.Content())
context.OutputNode.AddChild(r)
case xml.XML_PI_NODE:
name := node.Attr("name")
r := context.Output.CreatePINode(name, node.Content())
context.OutputNode.AddChild(r)
case xml.XML_NAMESPACE_DECL:
//in theory this should work
//in practice it's a little complicated due to the fact
//that namespace declarations don't map to the node type
//very well
//will need to revisit
//context.OutputNode.DeclareNamespace(node.Name(), node.Content())
case xml.XML_ELEMENT_NODE:
aname := node.Name()
r := context.Output.CreateElementNode(aname)
context.OutputNode.AddChild(r)
ns := node.Namespace()
if ns != "" {
//TODO: search through namespaces in-scope
prefix, _ := context.Style.NamespaceMapping[ns]
r.SetNamespace(prefix, ns)
} else {
//may need to explicitly reset to empty namespace
def := context.DefaultNamespace(context.OutputNode)
if def != "" {
r.SetNamespace("", "")
}
}
//copy namespace declarations
for _, decl := range node.DeclaredNamespaces() {
r.DeclareNamespace(decl.Prefix, decl.Uri)
}
old := context.OutputNode
context.OutputNode = r
if recursive {
//copy attributes
for _, attr := range node.Attributes() {
i.copyToOutput(attr, context, recursive)
}
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
i.copyToOutput(cur, context, recursive)
}
}
context.OutputNode = old
case xml.XML_DOCUMENT_NODE:
if recursive {
for cur := node.FirstChild(); cur != nil; cur = cur.NextSibling() {
i.copyToOutput(cur, context, recursive)
}
}
}
}