本文整理汇总了Golang中encoding/xml.CharData函数的典型用法代码### 示例。如果您正苦于以下问题:Golang CharData函数的具体用法?Golang CharData怎么用?Golang CharData使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了CharData函数的20个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: getTokenVariations

//This function creates variations on tokens without regards as to positions in the file.
func getTokenVariations(t xml.Token) []xml.Token {
    var result []xml.Token = make([]xml.Token, 0)
    switch t := t.(type) {
    case xml.CharData:
        {
            //If the token is a number try some random number
            if _, err := strconv.Atoi(string(t)); err == nil {
                result = append(result, xml.CharData(randInt(rand.Intn(15))))
            }

            result = append(result, xml.CharData(randString(rand.Intn(100))))
            return result
        }
    case xml.StartElement:
        {
            for k := range t.Attr {
                if _, err := strconv.Atoi(string(t.Attr[k].Value)); err == nil {
                    start := xml.CopyToken(t).(xml.StartElement)
                    start.Attr[k].Value = string(randInt(rand.Intn(15)))
                    result = append(result, start)
                }
                start := xml.CopyToken(t).(xml.StartElement)
                start.Attr[k].Value = string(randString(rand.Intn(100)))
                result = append(result, start)
            }
            return result
        }

    default:
        {
            return make([]xml.Token, 0) // No variations on non char tokens yet
        }
    }
}

开发者ID:Richardphp,项目名称:noms,代码行数:35,代码来源:fuzzy_test.go

示例2: swCustomized

func swCustomized() {
    //println("\nswCustomized")
    d := xml.NewDecoder(strings.NewReader(flatxml))
    e := xml.NewEncoder(os.Stdout)

    nesting := -1
    for {
        t, err := d.Token()
        if err == io.EOF {
            e.Flush()
            return
        }
        if err != nil {
            log.Fatal(err)
        }
        if _, ok := t.(xml.StartElement); ok {
            nesting++
        }
        if nesting > 0 {
            e.EncodeToken(xml.CharData(bytes.Repeat([]byte("  "), nesting)))
        }
        e.EncodeToken(t)
        e.EncodeToken(xml.CharData([]byte{'\n'}))
        if _, ok := t.(xml.EndElement); ok {
            nesting--
        }
        e.Flush()
    }
}

开发者ID:suntong,项目名称:lang,代码行数:29,代码来源:xml-beautify-string.go

示例3: marshalDescription

func marshalDescription(eltname string, e *xml.Encoder, desc map[string]template.HTML) error {
    var err error
    for lang, text := range desc {
        startElt := xml.StartElement{Name: xml.Name{Local: eltname}}

        startElt.Attr = []xml.Attr{
            xml.Attr{Name: xml.Name{Local: "lang"}, Value: lang},
        }

        err = e.EncodeToken(startElt)
        if err != nil {
            return err
        }

        err = e.EncodeToken(xml.CharData(string(text)))
        if err != nil {
            return err
        }

        err = e.EncodeToken(xml.EndElement{Name: startElt.Name})
        if err != nil {
            return err
        }

    }
    return nil
}

开发者ID:speedata,项目名称:ltxdoc,代码行数:27,代码来源:xmlout.go

示例4: StructToXML

// StructToXML writes an XMLNode to a xml.Encoder as tokens.
func StructToXML(e *xml.Encoder, node *XMLNode, sorted bool) error {
    e.EncodeToken(xml.StartElement{Name: node.Name, Attr: node.Attr})

    if node.Text != "" {
        e.EncodeToken(xml.CharData([]byte(node.Text)))
    } else if sorted {
        sortedNames := []string{}
        for k := range node.Children {
            sortedNames = append(sortedNames, k)
        }
        sort.Strings(sortedNames)

        for _, k := range sortedNames {
            for _, v := range node.Children[k] {
                StructToXML(e, v, sorted)
            }
        }
    } else {
        for _, c := range node.Children {
            for _, v := range c {
                StructToXML(e, v, sorted)
            }
        }
    }

    e.EncodeToken(xml.EndElement{Name: node.Name})
    return e.Flush()
}

开发者ID:40a,项目名称:bootkube,代码行数:29,代码来源:xml_to_struct.go

示例5: TrimSpace

// TrimSpace is a transformer function that replaces CDATA with blank
// characters with empty strings
func TrimSpace(parents *NodeList, in xml.Token) []xml.Token {
    switch t := in.(type) {
    case xml.CharData:
        return []xml.Token{xml.CharData(bytes.TrimSpace(t))}
    }
    return []xml.Token{in}
}

开发者ID:gravitational,项目名称:configure,代码行数:9,代码来源:xml.go

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