当前位置: 首页>>代码示例>>Golang>>正文


Golang Node.DeclaredNamespaces方法代码示例

本文整理汇总了Golang中github.com/ThomsonReutersEikon/gokogiri/xml.Node.DeclaredNamespaces方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.DeclaredNamespaces方法的具体用法?Golang Node.DeclaredNamespaces怎么用?Golang Node.DeclaredNamespaces使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/ThomsonReutersEikon/gokogiri/xml.Node的用法示例。


在下文中一共展示了Node.DeclaredNamespaces方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: DefaultNamespace

// Determine the default namespace currently defined in scope
func (context *ExecutionContext) DefaultNamespace(node xml.Node) string {
	//get the list of in-scope namespaces
	// any with a null prefix? return that
	decl := node.DeclaredNamespaces()
	for _, d := range decl {
		if d.Prefix == "" {
			return d.Uri
		}
	}
	return ""
}
开发者ID:xet7,项目名称:ratago,代码行数:12,代码来源:context.go

示例2: Apply


//.........这里部分代码省略.........
				}
			}
		}
		for _, c := range i.Children {
			c.Apply(node, context)
		}
		context.OutputNode = old

	case "comment":
		val, _ := i.evalChildrenAsText(node, context)
		r := context.Output.CreateCommentNode(val)
		context.OutputNode.AddChild(r)

	case "processing-instruction":
		name := i.Node.Attr("name")
		val, _ := i.evalChildrenAsText(node, context)
		//TODO: it is an error if val contains "?>"
		r := context.Output.CreatePINode(name, val)
		context.OutputNode.AddChild(r)

	case "attribute":
		aname := i.Node.Attr("name")
		if strings.ContainsRune(aname, '{') {
			aname = evalAVT(aname, node, context)
		}
		ahref := i.Node.Attr("namespace")
		if strings.ContainsRune(ahref, '{') {
			ahref = evalAVT(ahref, node, context)
		}
		val, _ := i.evalChildrenAsText(node, context)
		if ahref == "" {
			context.OutputNode.SetAttr(aname, val)
		} else {
			decl := context.OutputNode.DeclaredNamespaces()
			dfound := false
			for _, d := range decl {
				if ahref == d.Uri {
					dfound = true
					break
				}
			}
			if !dfound && ahref != XML_NAMESPACE {
				//TODO: increment val of generated prefix
				context.OutputNode.DeclareNamespace("ns_1", ahref)
			}
			//if a QName, we ignore the prefix when setting namespace
			if strings.Contains(aname, ":") {
				aname = aname[strings.Index(aname, ":")+1:]
			}
			context.OutputNode.SetNsAttr(ahref, aname, val)
		}
		//context.OutputNode.AddChild(a)

	case "value-of":
		e := xpath.Compile(i.Node.Attr("select"))
		disableEscaping := i.Node.Attr("disable-output-escaping") == "yes"

		context.RegisterXPathNamespaces(i.Node)
		content, _ := context.EvalXPathAsString(node, e)
		//don't bother creating a text node for an empty string
		if content != "" {
			if context.UseCDataSection(context.OutputNode) {
				olddata := context.OutputNode.LastChild()
				if olddata == nil || olddata.(*xml.CDataNode) == nil {
					r := context.Output.CreateCDataNode(content)
					context.OutputNode.AddChild(r)
开发者ID:xet7,项目名称:ratago,代码行数:67,代码来源:instruction.go

示例3: 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)
			}
		}
	}
}
开发者ID:xet7,项目名称:ratago,代码行数:75,代码来源:instruction.go


注:本文中的github.com/ThomsonReutersEikon/gokogiri/xml.Node.DeclaredNamespaces方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。