【问题标题】:How to parse the xml lines without field names in it using golang如何使用golang解析其中没有字段名的xml行
【发布时间】:2022-01-06 08:19:27
【问题描述】:

在使用 golang 时,我在解析 xml 行时遇到了困难,如下所示。 在这里,我也需要包含所有属性以进行解析。 请帮我解决这个问题

我的示例 xml 是

<vmap:data content="kid" cartoon="Popeye" id="1">
    <vmap:url status="found">
        <link>www.liink.com</link> 
    </vmap:url>
</vmap:data>

这个解析的结构格式是什么?

【问题讨论】:

    标签: xml go parsing struct xml-parsing


    【解决方案1】:

    您可以使用this 工具。

    在你的情况下,结果是:

    type Data struct {
        XMLName xml.Name `xml:"data"`
        Text    string   `xml:",chardata"`
        Content string   `xml:"content,attr"`
        Cartoon string   `xml:"cartoon,attr"`
        ID      string   `xml:"id,attr"`
        URL     struct {
            Text   string `xml:",chardata"`
            Status string `xml:"status,attr"`
            Link   string `xml:"link"`
        } `xml:"url"`
    } 
    
    

    【讨论】:

      猜你喜欢
      • 2018-02-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-02-15
      • 2021-11-04
      • 2016-08-17
      • 1970-01-01
      相关资源
      最近更新 更多