首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解封嵌套的OPML文档

解封嵌套的OPML文档
EN

Stack Overflow用户
提问于 2015-08-27 10:55:14
回答 1查看 80关注 0票数 1

我正在尝试解压缩一个简单的嵌套opml文档。当我嵌套opml并且无法决定结构时,问题就出现了。我把密码放在下面。请告诉我如何解析Outline结构的多层嵌套。

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

代码语言:javascript
复制
    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)
    }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-08-27 11:42:15

你需要使用指针

代码语言:javascript
复制
type Outline struct {
    Text string `xml:"text,attr"`
    Note string `xml:"_note,attr"`
    Outline *Outline `xml:"outline"`
}

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

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32247493

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档