我想解析示例中结构化的XML片段。我一直遇到值是空的。这是我正在使用的简化版本,仅用于显示问题。package mainimport ( "encoding/xml" "fmt")type Entry struct { VulnCveId string `xml:"entry>vuln:cve-id"`}func main() { v := Entry{} err := xml.Unmarshal([]byte(data), &v) if err != nil { fmt.Printf("error: %v", err) return } fmt.Println(v.VulnCveId)}const data = ` <entry id="CVE-2005-4895"> <vuln:vulnerable-configuration id="http://nvd.nist.gov/"> <cpe-lang:logical-test negate="false" operator="OR"> <cpe-lang:fact-ref name="cpe:/a:csilvers:gperftools:0.3" /> <cpe-lang:fact-ref name="cpe:/a:csilvers:gperftools:0.2" /> <cpe-lang:fact-ref name="cpe:/a:csilvers:gperftools:0.1" /> </cpe-lang:logical-test> </vuln:vulnerable-configuration> <vuln:vulnerable-software-list> <vuln:product>cpe:/a:csilvers:gperftools:0.3</vuln:product> <vuln:product>cpe:/a:csilvers:gperftools:0.1</vuln:product> <vuln:product>cpe:/a:csilvers:gperftools:0.2</vuln:product> </vuln:vulnerable-software-list> <vuln:cve-id>CVE-2005-4895</vuln:cve-id> <vuln:published-datetime>2012-07-25T15:55:01.273-04:00</vuln:published-datetime> <vuln:last-modified-datetime>2012-08-09T00:00:00.000-04:00</vuln:last-modified-datetime> <vuln:cvss> <cvss:base_metrics> <cvss:score>5.0</cvss:score> <cvss:access-vector>NETWORK</cvss:access-vector> <cvss:access-complexity>LOW</cvss:access-complexity> <cvss:authentication>NONE</cvss:authentication> <cvss:confidentiality-impact>NONE</cvss:confidentiality-impact> <cvss:integrity-impact>NONE</cvss:integrity-impact> <cvss:availability-impact>PARTIAL</cvss:availability-impact> <cvss:source>http://nvd.nist.gov</cvss:source>v.VulnCveId在此实例中为空。我究竟做错了什么?
3 回答
- 3 回答
- 0 关注
- 233 浏览
添加回答
举报
0/150
提交
取消