Skip to content

root.String() return "empty" string #21

Description

@irwinnoteam2009
import (
    "bytes"
    "encoding/xml"
    "fmt"
    "strings"
    "gopkg.in/xmlpath.v2"
    "golang.org/x/net/html/charset"
)

func main() {
    r := bytes.NewBuffer([]byte(d))
    decoder := xml.NewDecoder(r)
    decoder.CharsetReader = charset.NewReaderLabel
    root, _ := xmlpath.ParseDecoder(decoder)

        fmt.Printf("% x\n", root.Bytes()) 

    p, _ := xmlpath.Compile("list_boxes/boxes/*")
    iter := p.Iter(root)
    for iter.Next() {
        elem := iter.Node()
        s := strings.TrimSpace(elem.String())
        fmt.Printf("node: [%s]\n", s)
    }
}

const d = `
<?xml version="1.0" encoding="windows-1251" ?>
<list_boxes>
  <boxes>
    <box Name="1" Caption="Àäìèíèñòðàòîð" >
      <Flags/>
    </box>
    <box Name="2" Caption="Îïåðàòîð">
      <Flags/>
    </box>
    </boxes>
</list_boxes>`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions