dongyi5425 2018-12-18 13:46
浏览 116

去1.11.2 xml意外的EOF

I want to check if an submitted xml file is a valid xml or not so I check if it can be parsed. I do it like that:

const EmptyXml = `<?xml xmlns="http://www.w3.org/1999/xhtml"?>`

func CanParse(xmlData string) (bool, error) {
    if strings.TrimSpace(xmlData) == "" {
        return false, nil
    }
    type Tag struct {
        XMLName xml.Name
        Content string `xml:",innerxml"`
    }
    type Object struct {
        Items []Tag `xml:",any"`
    }
    var o *Object
    err := xml.Unmarshal([]byte(xmlData), &o)
    if err != nil {
        return false, err
    } else {
        return true, nil
    }
}

Sadly I end up with an error: unexpected EOF. Why is this?

Actually the method did work a month ago, and golang has not been updated since then so I´m still about to figure out what broke the method

https://goplay.space/#YxiyTbq8ww0

  • 写回答

1条回答 默认 最新

  • dongshan2680 2018-12-18 13:56
    关注

    It means that it expected an end tag. I've not done much XML recently, however I think you either have to add a closing </xml> or add question marks: <?xml xmlns="http://www.w3.org/1999/xhtml"?>

    评论

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法