本文整理汇总了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

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng