示例#1
0
func encEle(n tree.Elem, e *xml.Encoder) error {
	ele := xml.StartElement{
		Name: n.GetToken().(xml.StartElement).Name,
	}

	attrs := n.GetAttrs()
	ele.Attr = make([]xml.Attr, len(attrs))
	for i := range attrs {
		ele.Attr[i] = attrs[i].GetToken().(xml.Attr)
	}

	err := e.EncodeToken(ele)
	if err != nil {
		return err
	}

	if x, ok := n.(tree.Elem); ok {
		for _, i := range x.GetChildren() {
			err := encTok(i, e)
			if err != nil {
				return err
			}
		}
	}

	return e.EncodeToken(ele.End())
}
示例#2
0
func lang(c tree.Ctx, args ...tree.Result) (tree.Result, error) {
	lStr := args[0].String()

	var n tree.Elem

	for _, i := range c.NodeSet {
		if i.GetNodeType() == tree.NtElem {
			n = i.(tree.Elem)
		} else {
			n = i.GetParent()
		}

		for n.GetNodeType() != tree.NtRoot {
			if attr, ok := tree.GetAttribute(n, "lang", tree.XMLSpace); ok {
				return checkLang(lStr, attr.Value), nil
			}
			n = n.GetParent()
		}
	}

	return tree.Bool(false), nil
}