本文整理汇总了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
最后编辑: kuteng 文档更新时间: 2021-08-23 19:14 作者:kuteng