解组嵌套的 OPML 文档

我正在尝试解组一个简单的嵌套 opml 文档。当我嵌套了 opml 并且无法决定结构时,问题就出现了。我把代码放在下面。请让我知道如何解析结构的多级嵌套Outline。


http://play.golang.org/p/FobiL1JDdb


    package main


    import (

        "encoding/xml"

        "fmt"

    )


    var response = `<opml version='1.0'>

     <head>

      <title>More Cases</title>

      <expansionState>1,6,26</expansionState>

     </head>

     <body>

      <outline text='Testing' _note='indeterminate'>

       <outline text='Weekly' _status='indeterminate'>

       </outline>

       </outline>

     </body>

    </opml>`


    type Opml struct {

        XMLName xml.Name

        Version string `xml:"version,attr"`

        Head    Head   `xml:"head"`

        Body    Body   `xml:"body"`

    }


    type Head struct {

        Title          string `xml:"title"`

        ExpansionState string `xml:"expansionState"`

    }


    type Body struct {

        Outline Outline `xml:"outline"`

    }

    type Outline struct {

        Text string `xml:"text,attr"`

        Note string `xml:"_note,attr"`

    }


    func main() {


        fmt.Println("UnMrashal XML")

        opml := &Opml{}

        xml.Unmarshal([]byte(response), opml)

        fmt.Println(opml)

    }


小唯快跑啊
浏览 173回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Go