M
M
MOTORIST2016-07-12 13:22:14
go
MOTORIST, 2016-07-12 13:22:14

How to parse xml with nested html?

Hello!
There is an xml like this:

<?xml version="1.0" encoding="UTF-8"?>
<test>
  <title>Заголовок</tile>
        <description><p>01</p><p><a href="link">Ссылка</a></p></description>
</test>

I'm trying to parse it using "encoding/xml". Everything would be fine, but the description is empty.
type Test struct {
        Title string `xml:"title"`
  Description string `xml:"description"`
}

file, err := os.Open("test.xml")

  if err != nil{
    fmt.Printf("Error: %v", err)
  }
  defer file.Close()

  data, err := ioutil.ReadAll(file)

  if err != nil {
    fmt.Printf("Error: %v",err)
  }

  d := FictionBook{}
  err = xml.Unmarshal(data, &d)

  if err != nil {
    fmt.Printf("Error: %v",err)
  }

  fmt.Println(d)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2016-07-12
@MOTORIST

make a nested structure
example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question