コード例 #1
0
ファイル: xmltree.go プロジェクト: ChrisTrenkamp/goxpath
func setEle(opts *xmlbuilder.BuilderOpts, xmlTree xmlbuilder.XMLBuilder, ele xml.StartElement, ordrPos *int) {
	opts.NodePos = *ordrPos
	opts.Tok = ele
	opts.Attrs = opts.Attrs[0:0:cap(opts.Attrs)]
	opts.NS = make(map[xml.Name]string)
	opts.NodeType = tree.NtElem

	for i := range ele.Attr {
		attr := ele.Attr[i].Name
		val := ele.Attr[i].Value

		if (attr.Local == "xmlns" && attr.Space == "") || attr.Space == "xmlns" {
			opts.NS[attr] = val
		} else {
			opts.Attrs = append(opts.Attrs, &ele.Attr[i])
		}
	}

	if nstree, ok := xmlTree.(tree.NSElem); ok {
		ns := make(map[xml.Name]string)

		for _, i := range tree.BuildNS(nstree) {
			ns[i.Name] = i.Value
		}

		for k, v := range opts.NS {
			ns[k] = v
		}

		if ns[xml.Name{Local: "xmlns"}] == "" {
			delete(ns, xml.Name{Local: "xmlns"})
		}

		for k, v := range ns {
			opts.NS[k] = v
		}

		if xmlTree.GetNodeType() == tree.NtRoot {
			opts.NS[xml.Name{Space: "xmlns", Local: "xml"}] = tree.XMLSpace
		}
	}

	opts.AttrStartPos = len(opts.NS) + len(opts.Attrs) + *ordrPos
	*ordrPos = opts.AttrStartPos + 1
}
コード例 #2
0
ファイル: xmltree.go プロジェクト: ChrisTrenkamp/goxpath
func setNode(opts *xmlbuilder.BuilderOpts, xmlTree xmlbuilder.XMLBuilder, tok xml.Token, nt tree.NodeType, ordrPos *int) {
	opts.Tok = xml.CopyToken(tok)
	opts.NodeType = nt
	opts.NodePos = *ordrPos
	*ordrPos++
}