本文整理汇总了Golang中encoding/xml.Escape函数的典型用法代码示例。如果您正苦于以下问题:Golang Escape函数的具体用法?Golang Escape怎么用?Golang Escape使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Escape函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: String
func (s *stream) String() string {
var buf bytes.Buffer
buf.WriteString(`<stream:stream xmlns="`)
buf.WriteString(NsClient)
buf.WriteString(`" xmlns:stream="`)
buf.WriteString(NsStream)
buf.WriteString(`"`)
if s.To != "" {
buf.WriteString(` to="`)
xml.Escape(&buf, []byte(s.To))
buf.WriteString(`"`)
}
if s.From != "" {
buf.WriteString(` from="`)
xml.Escape(&buf, []byte(s.From))
buf.WriteString(`"`)
}
if s.Id != "" {
buf.WriteString(` id="`)
xml.Escape(&buf, []byte(s.Id))
buf.WriteString(`"`)
}
if s.Lang != "" {
buf.WriteString(` xml:lang="`)
xml.Escape(&buf, []byte(s.Lang))
buf.WriteString(`"`)
}
if s.Version != "" {
buf.WriteString(` version="`)
xml.Escape(&buf, []byte(s.Version))
buf.WriteString(`"`)
}
buf.WriteString(">")
return buf.String()
}
开发者ID:kissthink,项目名称:go-xmpp2,代码行数:35,代码来源:structs.go
示例2: Link
/*
映射端口
POST /ipc HTTP/1.1
HOST: 192.168.1.253:1900
Content-Type: text/xml; charset="utf-8"
Content-Length: 615
SOAPACTION: "urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping"
<?xml version="1.0"?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<u:AddPortMapping xmlns:u="urn:schemas-upnp-org:service:WANIPConnection:1">
<NewRemoteHost></NewRemoteHost>
<NewExternalPort>5678</NewExternalPort>
<NewProtocol>TCP</NewProtocol>
<NewInternalPort>3389</NewInternalPort>
<NewInternalClient>192.168.1.100</NewInternalClient>
<NewEnabled>1</NewEnabled>
<NewPortMappingDescription>xxxxxxxx</NewPortMappingDescription>
<NewLeaseDuration>0</NewLeaseDuration>
</u:AddPortMapping>
</s:Body>
</s:Envelope>
*/
func (this *UPnPService) Link(v *AddPortMapping) (err error) {
server_url := "http://" + this.ServerHost + "/ipc"
util.DEBUG.Logf("linking %s : %+v", server_url, v)
buf := bytes.NewBufferString("<?xml version=\"1.0\"?>\r\n")
buf.WriteString("<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">\r\n")
buf.WriteString("<s:Body>\r\n")
buf.WriteString("<u:AddPortMapping xmlns:u=\"urn:schemas-upnp-org:service:WANIPConnection:1\">\r\n")
buf.WriteString("<NewRemoteHost>")
xml.Escape(buf, []byte(v.NewRemoteHost))
buf.WriteString("</NewRemoteHost>\r\n")
buf.WriteString("<NewExternalPort>" + util.ToString(v.NewExternalPort) + "</NewExternalPort>\r\n")
buf.WriteString("<NewProtocol>")
xml.Escape(buf, []byte(v.NewProtocol))
buf.WriteString("</NewProtocol>\r\n")
buf.WriteString("<NewInternalPort>" + util.ToString(v.NewInternalPort) + "</NewInternalPort>\r\n")
buf.WriteString("<NewInternalClient>")
xml.Escape(buf, []byte(v.NewInternalClient))
buf.WriteString("</NewInternalClient>\r\n")
buf.WriteString("<NewEnabled>" + util.ToString(v.NewEnabled) + "</NewEnabled>\r\n")
buf.WriteString("<NewPortMappingDescription>")
xml.Escape(buf, []byte(v.NewPortMappingDescription))
buf.WriteString("</NewPortMappingDescription>\r\n")
buf.WriteString("<NewLeaseDuration>" + util.ToString(v.NewLeaseDuration) + "</NewLeaseDuration>\r\n")
buf.WriteString("</u:AddPortMapping>\r\n</s:Body>\r\n</s:Envelope>\r\n\r\n")
res, err := http.Post(server_url, "text/xml", buf)
if err != nil {
return
}
defer res.Body.Close()
b, err := ioutil.ReadAll(res.Body)
util.DEBUG.Log("\n[response]\n", string(b))
return
}
开发者ID:pa001024,项目名称:reflex,代码行数:58,代码来源:UPnP.go
示例3: Export
func (this *Element) Export(w io.Writer) {
io.WriteString(w, "<")
io.WriteString(w, this.Tag)
keys := make([]string, 0, len(this.attributes))
for k, _ := range this.attributes {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
v := this.attributes[k]
io.WriteString(w, " ")
xml.Escape(w, []byte(k))
io.WriteString(w, "=\"")
xml.Escape(w, []byte(v))
io.WriteString(w, "\"")
}
if this.IsSelfClosing() {
io.WriteString(w, " />")
} else {
io.WriteString(w, ">")
for _, c := range this.children {
c.Export(w)
}
io.WriteString(w, "</")
io.WriteString(w, this.Tag)
io.WriteString(w, ">")
}
}
开发者ID:badgerodon,项目名称:go,代码行数:28,代码来源:dom.go
示例4: atomServer
func (b *blog) atomServer() func(http.ResponseWriter, *http.Request) {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/atom+xml")
fullArticles := make([]fullArticle, len(b.articles))
for i, article := range b.articles {
content, err := b.renderContent(article.Url)
if err != nil {
http.NotFound(w, r)
return
}
var buf bytes.Buffer
xml.Escape(&buf, []byte(content))
fullArticles[i] = fullArticle{
Article: article,
Content: template.HTML(buf.String()),
}
}
atom := &atomData{
Articles: fullArticles,
}
sort.Sort(atom)
atom.Updated = atom.Articles[0].Article.Date
err := b.tmpl.ExecuteTemplate(w, "atom", atom)
if err != nil {
http.Error(w, err.Error(), 500)
}
}
}
开发者ID:joelgwebber,项目名称:j15r.com,代码行数:32,代码来源:blog.go
示例5: encodeMap
// encodeMap encodes a map to an XML plist dict.
func (e *Encoder) encodeMap(dict map[string]interface{}) error {
err := e.writeString("<dict>\n")
if err != nil {
return err
}
e.indentLevel++
for k, v := range dict {
_, err = e.bw.WriteString(e.indent() + "<key>")
if err != nil {
return err
}
xml.Escape(e.bw, []byte(k))
_, err = e.bw.WriteString("</key>\n")
if err != nil {
return err
}
err = e.encodeAny(v)
if err != nil {
return err
}
}
e.indentLevel--
err = e.writeString("</dict>\n")
if err != nil {
return err
}
return nil
}
开发者ID:nejstastnejsistene,项目名称:plist,代码行数:35,代码来源:encoder.go
示例6: escapeXML
func escapeXML(input []byte) []byte {
var buf *bytes.Buffer = bytes.NewBuffer(make([]byte, 0, len(input)+10))
xml.Escape(buf, input)
return buf.Bytes()
}
开发者ID:gk-turnip,项目名称:server,代码行数:7,代码来源:gksvg.go
示例7: encodeValue
func encodeValue(val reflect.Value) ([]byte, error) {
var b []byte
var err error
if val.Kind() == reflect.Ptr || val.Kind() == reflect.Interface {
if val.IsNil() {
return []byte("<value/>"), nil
}
val = val.Elem()
}
switch val.Kind() {
case reflect.Struct:
switch val.Interface().(type) {
case time.Time:
t := val.Interface().(time.Time)
b = []byte(fmt.Sprintf("<dateTime.iso8601>%s</dateTime.iso8601>", t.Format(iso8601)))
default:
b, err = encodeStruct(val)
}
case reflect.Map:
b, err = encodeMap(val)
case reflect.Slice:
b, err = encodeSlice(val)
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
b = []byte(fmt.Sprintf("<int>%s</int>", strconv.FormatInt(val.Int(), 10)))
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
b = []byte(fmt.Sprintf("<i4>%s</i4>", strconv.FormatUint(val.Uint(), 10)))
case reflect.Float32, reflect.Float64:
b = []byte(fmt.Sprintf("<double>%s</double>",
strconv.FormatFloat(val.Float(), 'g', -1, val.Type().Bits())))
case reflect.Bool:
if val.Bool() {
b = []byte("<boolean>1</boolean>")
} else {
b = []byte("<boolean>0</boolean>")
}
case reflect.String:
var buf bytes.Buffer
xml.Escape(&buf, []byte(val.String()))
if _, ok := val.Interface().(Base64); ok {
b = []byte(fmt.Sprintf("<base64>%s</base64>", buf.String()))
} else {
b = []byte(fmt.Sprintf("<value><string>%s</string></value>", buf.String()))
}
default:
return nil, fmt.Errorf("xmlrpc encode error: unsupported type")
}
if err != nil {
return nil, err
}
return []byte(fmt.Sprintf("%s", string(b))), nil
}
开发者ID:imvu,项目名称:Tetra,代码行数:58,代码来源:encoder.go
示例8: Exec
func (SitemapPlugin) Exec(topCtx mustache.Context) {
base_path := FromCtx(topCtx, "urls.base_path").(string)
f, err := os.OpenFile("compiled"+base_path+"sitemap.xml", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, os.ModePerm)
if err != nil {
log.Println("Error when create sitemap", err)
return
}
defer f.Close()
//自行拼接XML比官方的xml包还靠谱
f.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
f.WriteString("\n")
f.WriteString(`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`)
f.WriteString("\n")
production_url := FromCtx(topCtx, "site.config.production_url").(string)
production_url_base := FromCtx(topCtx, "site.config.production_url_base").(string)
f.WriteString("\t<url>\n")
f.WriteString("\t\t<loc>")
xml.Escape(f, []byte(production_url+"/")) //够弱智不? 竟然要传入一个io.Reader
f.WriteString("</loc>\n")
f.WriteString("\t</url>\n")
post_ids := FromCtx(topCtx, "db.posts.chronological").([]string)
posts := FromCtx(topCtx, "db.posts.dictionary").(map[string]Mapper)
for _, id := range post_ids {
f.WriteString("\t<url>\n")
post := posts[id]
f.WriteString("\t\t<loc>")
xml.Escape(f, []byte(production_url_base))
xml.Escape(f, []byte(post.Url()))
f.WriteString("</loc>\n")
f.WriteString(fmt.Sprintf("\t\t<lastmod>%s</lastmod>\n", post["date"])) // 是否应该抹除呢? 考虑中
f.WriteString("\t\t<changefreq>weekly</changefreq>\n")
f.WriteString("\t</url>\n")
}
f.WriteString(`</urlset>`)
f.Sync()
// ~_~ 大功告成!
}
开发者ID:wendal,项目名称:gor,代码行数:43,代码来源:plugins.go
示例9: escapeString
func (d *Decoder) escapeString(Value string) string {
var b *bytes.Buffer = bytes.NewBuffer([]byte{})
var writer io.Writer = b
var result string
xml.Escape(writer, []byte(Value))
result, _ = b.ReadString(0x00)
return result
}
开发者ID:magicmonty,项目名称:wbxml-go,代码行数:10,代码来源:decoder.go
示例10: Exec
func (SitemapPlugin) Exec(public string, topCtx mustache.Context) {
f, err := os.OpenFile(filepath.Join(public, "/sitemap.xml"), os.O_WRONLY|os.O_TRUNC|os.O_CREATE, DEFAULT_FILE_MODE)
if err != nil {
Log(ERROR, "When create sitemap %s", err)
return
}
defer f.Close()
//自行拼接XML比官方的xml包还靠谱
f.WriteString(`<?xml version="1.0" encoding="UTF-8"?>`)
f.WriteString("\n")
f.WriteString(`<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`)
f.WriteString("\n")
production_url := FromCtx(topCtx, "site.config.production_url").(string)
f.WriteString("\t<url>\n")
f.WriteString("\t\t<loc>")
xml.Escape(f, []byte(production_url+"/")) //够弱智不? 竟然要传入一个io.Reader
f.WriteString("</loc>\n")
f.WriteString("\t</url>\n")
post_ids := FromCtx(topCtx, "db.posts.chronological").([]string)
posts := FromCtx(topCtx, "db.posts.dictionary").(map[string]Mapper)
for _, id := range post_ids {
f.WriteString("\t<url>\n")
post := posts[id]
f.WriteString("\t\t<loc>")
xml.Escape(f, []byte(production_url))
xml.Escape(f, []byte(post.Url()))
f.WriteString("</loc>\n")
f.WriteString(fmt.Sprintf("\t\t<lastmod>%s</lastmod>\n", post["date"])) // 是否应该抹除呢? 考虑中
f.WriteString("\t\t<changefreq>weekly</changefreq>\n")
f.WriteString("\t</url>\n")
}
f.WriteString(`</urlset>`)
f.Sync()
// ~_~ 大功告成!
}
开发者ID:newblue,项目名称:neyo,代码行数:41,代码来源:plugins.go
示例11: writeXMLAttr
// Write a xml.Attr.
func writeXMLAttr(w io.Writer, attr xml.Attr) error {
if err := writeXMLName(w, attr.Name); err != nil {
return err
}
if _, err := w.Write([]byte{'=', '\''}); err != nil {
return err
}
xml.Escape(w, []byte(attr.Value))
if _, err := w.Write([]byte{'\''}); err != nil {
return err
}
return nil
}
开发者ID:nitpicker,项目名称:livehouse_xmpp_muc_bridge,代码行数:14,代码来源:xml.go
示例12: postIssueComment
func postIssueComment(ctxt appengine.Context, id, comment string) error {
cfg, err := oauthConfig(ctxt)
if err != nil {
return fmt.Errorf("oauthconfig: %v", err)
}
var tok oauth.Token
if err := app.ReadMeta(ctxt, "codelogin.token", &tok); err != nil {
return fmt.Errorf("reading token: %v", err)
}
tr := &oauth.Transport{
Config: cfg,
Token: &tok,
Transport: urlfetch.Client(ctxt).Transport,
}
client := tr.Client()
var buf bytes.Buffer
buf.WriteString(`<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009'>
<content type='html'>`)
xml.Escape(&buf, []byte(comment))
buf.WriteString(`</content>
<author>
<name>ignored</name>
</author>
<issues:updates>
</issues:updates>
</entry>
`)
u := "https://code.google.com/feeds/issues/p/go/issues/" + id + "/comments/full"
req, err := http.NewRequest("POST", u, &buf)
if err != nil {
return fmt.Errorf("write: %v", err)
}
req.Header.Set("Content-Type", "application/atom+xml")
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("write: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 201 {
buf.Reset()
io.Copy(&buf, resp.Body)
return fmt.Errorf("write: %v\n%s", resp.Status, buf.String())
}
return nil
}
开发者ID:lambdaX,项目名称:rsc.godev,代码行数:49,代码来源:login.go
示例13: encodeString
// encodeString encodes a string to the XML plist format.
func (e *Encoder) encodeString(str string) error {
_, err := e.bw.WriteString(e.indent() + "<string>")
if err != nil {
return err
}
xml.Escape(e.bw, []byte(str))
_, err = e.bw.WriteString("</string>\n")
if err != nil {
return err
}
return nil
}
开发者ID:nejstastnejsistene,项目名称:plist,代码行数:16,代码来源:encoder.go
示例14: encodeStruct
// encodeStruct encodes a struct to an XML plist dict.
func (e *Encoder) encodeStruct(rv reflect.Value) error {
err := e.writeString("<dict>\n")
if err != nil {
return err
}
e.indentLevel++
for i := 0; i < rv.NumField(); i++ {
rt := rv.Type()
f := rt.Field(i)
name := f.Tag.Get("plist")
if name == "-" {
continue
}
if name == "" {
name = f.Name
}
_, err = e.bw.WriteString(e.indent() + "<key>")
if err != nil {
return err
}
xml.Escape(e.bw, []byte(name))
_, err = e.bw.WriteString("</key>\n")
if err != nil {
return err
}
err = e.encodeAny(rv.Field(i).Interface())
if err != nil {
return err
}
}
e.indentLevel--
err = e.writeString("</dict>\n")
if err != nil {
return err
}
return nil
}
开发者ID:nejstastnejsistene,项目名称:plist,代码行数:45,代码来源:encoder.go
示例15: encodeValue
// TODO: base64
func (e *encoder) encodeValue(val reflect.Value) {
if val.Kind() == reflect.Ptr || val.Kind() == reflect.Interface {
val = val.Elem()
}
fmt.Fprint(e, "<value>")
switch val.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
fmt.Fprintf(e, "<int>%d</int>", val.Int())
case reflect.Bool:
var n int
if val.Bool() {
n = 1
} else {
n = 0
}
fmt.Fprintf(e, "<boolean>%d</boolean>", n)
case reflect.String:
fmt.Fprint(e, "<string>")
xml.Escape(e, []byte(val.String()))
fmt.Fprint(e, "</string>")
case reflect.Float32, reflect.Float64:
fmt.Fprintf(e, "<double>%f</double>", val.Float())
case reflect.Struct:
if t, isTime := val.Interface().(time.Time); isTime {
fmt.Fprintf(e, "<dateTime.iso8601>%s</dateTime.iso8601>", t.Format(iso8601))
} else {
e.encodeStruct(val)
}
case reflect.Slice:
e.encodeSlice(val)
}
fmt.Fprint(e, "</value>")
}
开发者ID:pocke,项目名称:go-xmlrpc,代码行数:37,代码来源:encoder.go
示例16: Link
// Link begins a link named "name", with the specified title.
// Standard Reference: http://www.w3.org/TR/SVG11/linking.html#Links
func (svg *SVG) Link(href string, title string) {
svg.printf("<a xlink:href=\"%s\" xlink:title=\"", href)
xml.Escape(svg.Writer, []byte(title))
svg.println("\">")
}
开发者ID:stanim,项目名称:svgof,代码行数:7,代码来源:svg.go
示例17: write
func write(id int, ch *Change) error {
var buf bytes.Buffer
buf.WriteString(`<?xml version='1.0' encoding='UTF-8'?>
<entry xmlns='http://www.w3.org/2005/Atom' xmlns:issues='http://schemas.google.com/projecthosting/issues/2009'>
<content type='html'>`)
xml.Escape(&buf, []byte(ch.Comment))
buf.WriteString(`</content>
<author>
<name>ignored</name>
</author>
<issues:updates>
`)
tag := func(t, data string) {
buf.WriteString(` ` + t)
xml.Escape(&buf, []byte(data))
buf.WriteString(`</` + t[1:])
}
if ch.Summary != "" {
tag("<issues:summary>", ch.Summary)
}
if ch.Status != "" {
status := ch.Status
merge := ""
if strings.HasPrefix(status, "Duplicate ") {
merge = strings.TrimPrefix(status, "Duplicate ")
status = "Duplicate"
}
tag("<issues:status>", status)
if merge != "" {
tag("<issues:mergedIntoUpdate>", merge)
}
}
if ch.Owner != "" {
tag("<issues:ownerUpdate>", ch.Owner)
}
for _, l := range ch.Label {
tag("<issues:label>", l)
}
for _, cc := range ch.CC {
tag("<issues:ccUpdate>", cc)
}
buf.WriteString(`
</issues:updates>
</entry>
`)
// Done with XML!
u := "https://code.google.com/feeds/issues/p/" + *project + "/issues/" + fmt.Sprint(id) + "/comments/full"
req, err := http.NewRequest("POST", u, &buf)
if err != nil {
return fmt.Errorf("write: %v", err)
}
req.Header.Set("Content-Type", "application/atom+xml")
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("write: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != 201 {
buf.Reset()
io.Copy(&buf, resp.Body)
return fmt.Errorf("write: %v\n%s", resp.Status, buf.String())
}
return nil
}
开发者ID:0x7cc,项目名称:rsc,代码行数:67,代码来源:issue.go
示例18: HtmlXML
func (p *Post) HtmlXML() string {
var buf bytes.Buffer
xml.Escape(&buf, []byte(p.Html))
return buf.String()
}
开发者ID:markpasc,项目名称:cares,代码行数:5,代码来源:post.go
示例19: escape
func escape(w io.Writer, str string) {
xml.Escape(w, []uint8(str))
}
开发者ID:gnanderson,项目名称:go-erx,代码行数:3,代码来源:XMLFormatter.go
示例20: Escape
func (this *writer) Escape(s string) []byte {
this.buf.Reset()
xml.Escape(this.buf, []byte(s))
return this.buf.Bytes()
}
开发者ID:jppr,项目名称:element,代码行数:5,代码来源:xml.go
注:本文中的encoding/xml.Escape函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论