本文整理汇总了Golang中encoding/xml.StartElement.Copy方法的典型用法代码示例。如果您正苦于以下问题:Golang StartElement.Copy方法的具体用法?Golang StartElement.Copy怎么用?Golang StartElement.Copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类encoding/xml.StartElement
的用法示例。
在下文中一共展示了StartElement.Copy方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: genSchema
func genSchema(commands *commandsxml.CommandsXML, lang string) ([]byte, error) {
var outbuf bytes.Buffer
enc := xml.NewEncoder(&outbuf)
enc.Indent("", " ")
namespace := fmt.Sprintf("urn:speedata.de:2009/publisher/%s", lang)
grammar := xml.StartElement{Name: xml.Name{Local: "grammar", Space: RELAXNG}}
grammar.Attr = []xml.Attr{
{Name: xml.Name{Local: "xmlns:a"}, Value: "http://relaxng.org/ns/compatibility/annotations/1.0"},
{Name: xml.Name{Local: "xmlns:sch"}, Value: "http://purl.oclc.org/dsdl/schematron"},
{Name: xml.Name{Local: "ns"}, Value: namespace},
{Name: xml.Name{Local: "datatypeLibrary"}, Value: "http://www.w3.org/2001/XMLSchema-datatypes"},
}
enc.EncodeToken(xml.Comment("Do not edit this file. Auto generated from commands.xml with sphelper."))
enc.EncodeToken(xml.CharData("\n"))
enc.EncodeToken(grammar)
sch := xml.StartElement{Name: xml.Name{Local: "sch:ns"}}
sch.Attr = []xml.Attr{
{Name: xml.Name{Local: "prefix"}, Value: "t"},
{Name: xml.Name{Local: "uri"}, Value: namespace},
}
enc.EncodeToken(sch)
enc.EncodeToken(sch.End())
start := xml.StartElement{Name: xml.Name{Local: "start"}}
enc.EncodeToken(start)
choice := xml.StartElement{Name: xml.Name{Local: "choice"}}
enc.EncodeToken(choice)
refLayout := xml.StartElement{Name: xml.Name{Local: "ref"}}
refLayout.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: "e_Layout"}}
refInclude := xml.StartElement{Name: xml.Name{Local: "ref"}}
refInclude.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: "e_Include"}}
enc.EncodeToken(refLayout)
enc.EncodeToken(refLayout.End())
enc.EncodeToken(refInclude)
enc.EncodeToken(refInclude.End())
enc.EncodeToken(choice.End())
enc.EncodeToken(start.End())
attributeElement := xml.StartElement{Name: xml.Name{Local: "attribute"}}
for _, cmd := range commands.Commands {
enc.Flush()
for _, r := range cmd.Rules {
if r.Lang == lang {
outbuf.WriteString(r.Rules)
}
}
def := xml.StartElement{Name: xml.Name{Local: "define"}}
def.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: "e_" + cmd.En}}
enc.EncodeToken(def)
elt := xml.StartElement{Name: xml.Name{Local: "element"}}
elt.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: commands.TranslateCommand("en", lang, cmd.En)}}
enc.EncodeToken(elt)
doc := xml.StartElement{Name: xml.Name{Local: "a:documentation"}}
enc.EncodeToken(doc)
enc.EncodeToken(xml.CharData(cmd.GetCommandDescription(lang)))
enc.EncodeToken(doc.End())
for _, attr := range cmd.Attributes {
if attr.Optional == "yes" {
enc.EncodeToken(optionalElement.Copy())
}
attname, _ := commands.TranslateAttribute("en", lang, cmd.En, attr.En, "-")
attelt := attributeElement.Copy()
attelt.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: attname}}
enc.EncodeToken(attelt)
doc := xml.StartElement{Name: xml.Name{Local: "a:documentation"}}
enc.EncodeToken(doc)
enc.EncodeToken(xml.CharData(attr.GetDescription(lang)))
enc.EncodeToken(doc.End())
if len(attr.Choice) > 0 {
enc.EncodeToken(choiceElement.Copy())
for _, choice := range attr.Choice {
enc.EncodeToken(valueElement.Copy())
enc.EncodeToken(xml.CharData(choice.GetValue(lang)))
enc.EncodeToken(valueElement.End())
doc := xml.StartElement{Name: xml.Name{Local: "a:documentation"}}
enc.EncodeToken(doc)
enc.EncodeToken(xml.CharData(choice.GetDescription(lang)))
enc.EncodeToken(doc.End())
}
if attr.AllowXPath == "yes" {
data := xml.StartElement{Name: xml.Name{Local: "data"}}
data.Attr = []xml.Attr{{Name: xml.Name{Local: "type"}, Value: "string"}}
enc.EncodeToken(data)
param := xml.StartElement{Name: xml.Name{Local: "param"}}
param.Attr = []xml.Attr{{Name: xml.Name{Local: "name"}, Value: "pattern"}}
enc.EncodeToken(param)
//.........这里部分代码省略.........