Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用go提取xml属性_Xml_Go_Xml Parsing - Fatal编程技术网

用go提取xml属性

用go提取xml属性,xml,go,xml-parsing,Xml,Go,Xml Parsing,如何从之类的元素中提取“id”属性?它嵌套在下。我最初的尝试类似于xml:“entry>cwe,id,attr”两种方法: 1/继续获取标记(),直到元素的名称cwe 然后,结构“CweXml”可以提取id属性: type CweXml struct { Id string `xml:"id,attr"` } 2/或者从entry开始,但是在这种情况下,您需要一个结构,它将包含CweXmlstruct type EntryXml struct { Cwe CweXml `xml

如何从
之类的元素中提取“id”属性?它嵌套在
下。我最初的尝试类似于
xml:“entry>cwe,id,attr”

两种方法:

1/继续获取
标记()
,直到元素的名称
cwe

然后,结构“CweXml”可以提取id属性:

type CweXml struct {
    Id string `xml:"id,attr"`
}
2/或者从
entry
开始,但是在这种情况下,您需要一个结构,它将包含
CweXml
struct

type EntryXml struct {
    Cwe CweXml `xml:"cwe"`
}
在这种情况下,您将在
entryXml.Cwe.id
中找到id