本文整理汇总了Golang中encoding/xml.EscapeText函数的典型用法代码示例。如果您正苦于以下问题:Golang EscapeText函数的具体用法?Golang EscapeText怎么用?Golang EscapeText使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了EscapeText函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: encodeDomainCheck
func encodeDomainCheck(buf *bytes.Buffer, domains []string, extFee bool) error {
buf.Reset()
buf.WriteString(xmlCommandPrefix)
buf.WriteString(`<check>`)
buf.WriteString(`<domain:check xmlns:domain="urn:ietf:params:xml:ns:domain-1.0">`)
for _, domain := range domains {
buf.WriteString(`<domain:name>`)
xml.EscapeText(buf, []byte(domain))
buf.WriteString(`</domain:name>`)
}
buf.WriteString(`</domain:check>`)
buf.WriteString(`</check>`)
if extFee {
// Extensions
buf.WriteString(`<extension>`)
// CentralNic fee extension
buf.WriteString(`<fee:check xmlns:fee="urn:ietf:params:xml:ns:fee-0.5">`)
for _, domain := range domains {
buf.WriteString(`<fee:domain>`)
buf.WriteString(`<fee:name>`)
xml.EscapeText(buf, []byte(domain))
buf.WriteString(`</fee:name>`)
buf.WriteString(`<fee:command>create</fee:command>`)
buf.WriteString(`</fee:domain>`)
}
buf.WriteString(`</fee:check>`)
buf.WriteString(`</extension>`)
}
buf.WriteString(xmlCommandSuffix)
return nil
}
开发者ID:mythic-beasts,项目名称:epp,代码行数:35,代码来源:check.go
示例2: value_to_xml
func value_to_xml(v interface{}) (string, error) {
switch t := v.(type) {
case int, int8, int64, int32, *int, *int8, *int64, *int32:
return fmt.Sprintf("<int>%d</int>", t), nil
case string:
buf := bytes.NewBuffer(make([]byte, 0))
err := xml.EscapeText(buf, []byte(t))
if err != nil {
return "", err
}
return fmt.Sprintf("<string>%s</string>", buf.String()), nil
case []byte:
return fmt.Sprintf("<base64>%s</base64>", base64.StdEncoding.EncodeToString(t)), nil
case float32, float64, *float32, *float64:
return fmt.Sprintf("<double>%f</double>", t), nil
case bool:
return fmt.Sprintf("<boolean>%d</boolean>", btoi(t)), nil
case time.Time:
buf := bytes.NewBuffer(make([]byte, 0))
err := xml.EscapeText(buf, []byte(t.Format(time_ISO8601_FORMAT)))
if err != nil {
return "", err
}
return fmt.Sprintf("<dateTime.iso8601>%s</dateTime.iso8601>", buf.String()), nil
case *time.Time:
buf := bytes.NewBuffer(make([]byte, 0))
err := xml.EscapeText(buf, []byte(t.Format(time_ISO8601_FORMAT)))
if err != nil {
return "", err
}
return fmt.Sprintf("<dateTime.iso8601>%s</dateTime.iso8601>", buf.String()), nil
case []interface{}:
tmp_str_arr := []string{"<array><data>"}
for _, v := range t {
subval, err := value_to_xml(v)
if err != nil {
return "", err
}
tmp_str_arr = append(tmp_str_arr, fmt.Sprintf("<value>%s</value>", subval))
}
tmp_str_arr = append(tmp_str_arr, "</data></array>")
return strings.Join(tmp_str_arr, ""), nil
case map[string]interface{}:
tmp_str_arr := []string{"<struct>"}
for name, item := range t {
tmp_str_arr = append(tmp_str_arr, "<member>")
tmp_str_arr = append(tmp_str_arr, fmt.Sprintf("<name>%s</name>", name))
subval, err := value_to_xml(item)
if err != nil {
return "", err
}
tmp_str_arr = append(tmp_str_arr, fmt.Sprintf("<value>%s</value>", subval))
tmp_str_arr = append(tmp_str_arr, "</member>")
}
tmp_str_arr = append(tmp_str_arr, "</struct>")
return strings.Join(tmp_str_arr, ""), nil
default:
return "", errors.New("Unrecognized type")
}
}
开发者ID:yuzhibo-hongshu,项目名称:goxmpp,代码行数:60,代码来源:xep0009.go
示例3: main
func main() {
inputReader := strings.NewReader(input)
decoder := xml.NewDecoder(inputReader)
for {
// Read tokens from the XML document in a stream.
t, _ := decoder.Token()
if t == nil {
break
}
// Inspect the type of the token just read.
//fmt.Printf("\n<!--%#v-->\n", t)
switch x := t.(type) {
case xml.StartElement:
fmt.Printf("<%s", x.Name.Local)
for _, attr := range x.Attr {
fmt.Printf(" %s=\"", attr.Name.Local)
xml.EscapeText(os.Stdout, []byte(attr.Value))
os.Stdout.Write([]byte{'"'})
}
fmt.Printf(">")
case xml.CharData:
xml.EscapeText(os.Stdout, bytes.TrimSpace(x))
case xml.EndElement:
fmt.Printf("</%s>\n", x.Name.Local)
}
}
}
开发者ID:suntong,项目名称:lang,代码行数:29,代码来源:parser03B.go
示例4: genQuery
// meh3
func genQuery(query string, args dict) []byte {
var out bytes.Buffer
out.WriteString("<query")
for key, val := range args {
fmt.Fprintf(&out, " %s=\"", key)
xml.EscapeText(&out, []byte(val))
out.WriteString("\"")
}
out.WriteString(">")
xml.EscapeText(&out, []byte(query))
out.WriteString("</query>\r\n.\r\n")
return out.Bytes()
}
开发者ID:carltondouglas,项目名称:stuff,代码行数:16,代码来源:main.go
示例5: ToXML
// ToXML marshal map[string]string to xmlWriter with xml format, the root node name is xml.
// NOTE: This function assumes the key of m map[string]string are legitimate xml name string
// that does not contain the required escape character!
func (x *Xml) ToXML(xmlWriter io.Writer, m map[string]string) (err error) {
if xmlWriter == nil {
return errors.New("nil xmlWriter")
}
if _, err = io.WriteString(xmlWriter, "<xml>"); err != nil {
return
}
for k, v := range m {
if _, err = io.WriteString(xmlWriter, "<"+k+">"); err != nil {
return
}
if err = xml.EscapeText(xmlWriter, []byte(v)); err != nil {
return
}
if _, err = io.WriteString(xmlWriter, "</"+k+">"); err != nil {
return
}
}
if _, err = io.WriteString(xmlWriter, "</xml>"); err != nil {
return
}
return
}
开发者ID:api4me,项目名称:next,代码行数:29,代码来源:xml.go
示例6: WriteQuad
func (w *Writer) WriteQuad(q quad.Quad) error {
if w.err != nil {
return w.err
}
if !w.written {
if _, err := w.w.Write([]byte(header)); err != nil {
return err
}
w.written = true
w.nodes = make(map[string]int)
}
s := w.writeNode(quad.StringOf(q.Subject))
o := w.writeNode(quad.StringOf(q.Object))
if w.err != nil {
return w.err
}
_, w.err = fmt.Fprintf(w.w, "\t\t<edge source=\"n%d\" target=\"n%d\"><data key=\"d1\">", s, o)
if w.err != nil {
return w.err
}
if w.err = xml.EscapeText(w.w, []byte(quad.StringOf(q.Predicate))); w.err != nil {
return w.err
}
_, w.err = w.w.Write([]byte("</data></edge>\n"))
return w.err
}
开发者ID:dennwc,项目名称:cayley,代码行数:26,代码来源:graphml.go
示例7: writeFault
// Return an XML-RPC fault
func writeFault(out io.Writer, code int, msg string) {
fmt.Fprintf(out, `<?xml version="1.0"?>
<methodResponse>
<fault>
<value>
<struct>
<member>
<name>faultCode</name>
<value><int>%d</int></value>
</member>
<member>
<name>faultString</name>
<value>`, code)
err := xml.EscapeText(out, []byte(msg))
fmt.Fprintf(out, `</value>
</member>
</struct>
</value>
</fault>
</methodResponse>`)
// XXX dump the error to Stderr for now
if err != nil {
fmt.Fprintf(os.Stderr, "Cannot write fault#%d(%s): %v\n", code, msg,
err)
}
}
开发者ID:dancebear,项目名称:go-xmlrpc,代码行数:28,代码来源:server.go
示例8: httpAPIVoiceMessage
// The HTTP voice processing endpoint reads DTMF (input from Twilio request) and translates it into a statement and execute.
func (sh *WebShell) httpAPIVoiceMessage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/xml")
w.Header().Set("Cache-Control", "must-revalidate")
w.WriteHeader(http.StatusOK)
digits := r.FormValue("Digits")
decodedLetters := voiceDecodeDTMF(digits)
log.Printf("Voice message got digits: %s (decoded - %s)", digits, decodedLetters)
if cmd := sh.cmdFind(decodedLetters); cmd == "" {
// PIN mismatch
w.Write([]byte(`<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Say>Sorry</Say>
<Hangup/>
</Response>
`))
} else {
// Speak the command result and repeat
output := sh.cmdRun(cmd, sh.WebTimeoutSec, sh.WebTruncateLen, true, true)
var escapeOutput bytes.Buffer
if err := xml.EscapeText(&escapeOutput, []byte(output)); err != nil {
log.Printf("XML escape failed - %v", err)
}
w.Write([]byte(fmt.Sprintf(`<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Gather action="%s%s" method="POST" timeout="15" finishOnKey="#" numDigits="1000">
<Say voice="man" loop="1" language="en">%s over</Say>
</Gather>
</Response>
`, sh.VoiceEndpointPrefix, sh.VoiceProcEndpoint, escapeOutput.String())))
}
}
开发者ID:HouzuoGuo,项目名称:websh,代码行数:32,代码来源:main.go
示例9: serializeItem
func serializeItem(k string, v interface{}, w io.Writer) {
w.Write([]byte(`<item key="`))
xml.EscapeText(w, []byte(k))
w.Write([]byte(`">`))
switch i := v.(type) {
case string:
xml.EscapeText(w, []byte(i))
case NestedStringMap:
serializeMap(i, w)
case []NestedStringMap:
serializeNSMArray(i, w)
case []string:
serializeStringArray(i, w)
}
w.Write([]byte(`</item>`))
}
开发者ID:mythic-beasts,项目名称:opensrs,代码行数:16,代码来源:client.go
示例10: NewCommand
func (s *Shell) NewCommand(cmd string, arguments []string) (string, error) {
var buf = bytes.NewBuffer(make([]byte, 0, len(cmd)))
if e := xml.EscapeText(buf, []byte(cmd)); nil != e {
return "", e
}
env := &envelope.CreateCommand{Uuid(), s.Id, strings.Replace(buf.String(), """, """, -1), arguments}
reader, err := s.Deliver(bytes.NewBufferString(env.Xml()))
if err != nil {
return "", err
}
defer closeReader(reader)
decoder := xml.NewDecoder(reader)
if err := ReadEnvelopeBody(decoder); nil != err {
return "", err
}
ok, err := locateElements(decoder, []string{"CommandResponse", "CommandId"})
if nil != err {
return "", errors.New("locate 'Envelope/Body/CommandResponse/CommandId' failed, " + err.Error())
}
if !ok {
return "", ElementNotExists("Envelope/Body/CommandResponse/CommandId")
}
id, e := readXmlText(decoder)
if nil != e {
return "", errors.New("read CommandId from the response failed, " + e.Error())
}
return id, nil
}
开发者ID:runner-mei,项目名称:wsman,代码行数:34,代码来源:shell.go
示例11: FormatMapToXML
// 格式化 map[string]string 为 xml 格式
// 用于微信支付
func FormatMapToXML(xmlWriter io.Writer, Map map[string]string) (err error) {
if xmlWriter == nil {
return errors.New("xmlWriter == nil")
}
_, err = io.WriteString(xmlWriter, "<xml>\n")
if err != nil {
return
}
for key, value := range Map {
_, err = io.WriteString(xmlWriter, "<"+key+">")
if err != nil {
return
}
if err = xml.EscapeText(xmlWriter, []byte(value)); err != nil {
return
}
_, err = io.WriteString(xmlWriter, "</"+key+">\n")
if err != nil {
return
}
}
_, err = io.WriteString(xmlWriter, "</xml>")
if err != nil {
return
}
return
}
开发者ID:daqinbuyi,项目名称:wechat,代码行数:33,代码来源:xml.go
示例12: escapeXml
func escapeXml(in string) string {
var out bytes.Buffer
err := xml.EscapeText(&out, []byte(in))
if err != nil {
panic("Could not escape XML: " + err.Error())
}
return out.String()
}
开发者ID:joansais,项目名称:go-practices,代码行数:8,代码来源:syntax_test.go
示例13: printText
func (this *Node) printText() []byte {
val := []byte(this.Value)
if len(this.Parent.Children) > 1 {
return val
}
var b bytes.Buffer
xml.EscapeText(&b, val)
return b.Bytes()
}
开发者ID:sdgoij,项目名称:go-pkg-xmlx,代码行数:9,代码来源:node.go
示例14: escapeXml
func escapeXml(s string) string {
buf := new(bytes.Buffer)
buf.Grow(len(s))
err := xml.EscapeText(buf, []byte(s))
if err != nil {
panic(err)
}
return buf.String()
}
开发者ID:realduke2000,项目名称:gxmpp,代码行数:9,代码来源:stanza.go
示例15: escapeXmlText
func escapeXmlText(s string) (string, error) {
buffer := new(bytes.Buffer)
err := xml.EscapeText(buffer, []byte(s))
if err != nil {
return "", err
}
return buffer.String(), nil
}
开发者ID:jac0,项目名称:govue,代码行数:10,代码来源:svue_api.go
示例16: encodeRequestAction
// encodeRequestAction is a hacky way to create an encoded SOAP envelope
// containing the given action. Experiments with one router have shown that it
// 500s for requests where the outer default xmlns is set to the SOAP
// namespace, and then reassigning the default namespace within that to the
// service namespace. Hand-coding the outer XML to work-around this.
func encodeRequestAction(actionNamespace, actionName string, inAction interface{}) ([]byte, error) {
requestBuf := new(bytes.Buffer)
requestBuf.WriteString(soapPrefix)
requestBuf.WriteString(`<u:`)
xml.EscapeText(requestBuf, []byte(actionName))
requestBuf.WriteString(` xmlns:u="`)
xml.EscapeText(requestBuf, []byte(actionNamespace))
requestBuf.WriteString(`">`)
if inAction != nil {
if err := encodeRequestArgs(requestBuf, inAction); err != nil {
return nil, err
}
}
requestBuf.WriteString(`</u:`)
xml.EscapeText(requestBuf, []byte(actionName))
requestBuf.WriteString(`>`)
requestBuf.WriteString(soapSuffix)
return requestBuf.Bytes(), nil
}
开发者ID:nilcons-contrib,项目名称:go-ethereum,代码行数:24,代码来源:soap.go
示例17: Excerpt
func (p Post) Excerpt() string {
r := regexp.MustCompile("<p>(.+?)</p>")
result := r.FindStringSubmatch(p.htmlContent)
if len(result) > 1 {
buf := new(bytes.Buffer)
xml.EscapeText(buf, []byte(result[1]))
return buf.String() + " ..."
}
return ""
}
开发者ID:rangilin,项目名称:glowing-dangerzone,代码行数:10,代码来源:post.go
示例18: Connect
// Connect connects and logs in to a vSphere host.
func Connect(host, user, pwd string) (*Vsphere, error) {
header := http.Header{
"Content-Type": []string{`text/xml; charset=UTF-8`},
"SOAPAction": []string{`"urn:vim25/5.5"`},
}
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
v := &Vsphere{
url: &url.URL{
Scheme: "https",
Host: host,
Path: "/sdk",
},
header: header,
client: &http.Client{
Timeout: time.Minute,
Transport: &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
},
},
cookies: jar,
}
uuid := struct {
UUID string `xml:"Body>RetrieveServiceContentResponse>returnval>about>instanceUuid"`
}{}
if err := v.call(soapConnect, &uuid); err != nil {
return nil, err
}
if uuid.UUID == "" {
return nil, fmt.Errorf("vsphere: no UUID during connect")
}
userbuf := new(bytes.Buffer)
pwdbuf := new(bytes.Buffer)
xml.EscapeText(userbuf, []byte(user))
xml.EscapeText(pwdbuf, []byte(pwd))
if err := v.call(fmt.Sprintf(soapLogin, userbuf, pwdbuf), nil); err != nil {
return nil, err
}
return v, nil
}
开发者ID:noblehng,项目名称:bosun,代码行数:43,代码来源:vsphere.go
示例19: escape
func escape(s string) string {
for i := 0; i < len(s); i++ {
switch s[i] {
case '"', '&', '\'', '<', '>':
b := bytes.NewBuffer(nil)
xml.EscapeText(b, []byte(s))
return b.String()
}
}
return s
}
开发者ID:tessavitabile,项目名称:logkeeper,代码行数:11,代码来源:xml.go
示例20: SetColor
func (res *Resources) SetColor(name, value string) *Resources {
for index, _ := range res.Colors {
if name == res.Colors[index].Name {
m := new(bytes.Buffer)
xml.EscapeText(m, []byte(value))
res.Colors[index].Value = m.String()
break
}
}
return res
}
开发者ID:snakehopper,项目名称:goandroid,代码行数:11,代码来源:resources.go
注:本文中的encoding/xml.EscapeText函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论