Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何从像这样的元素中提取“id”属性<vuln:cwe id="CWE-189" />?这是嵌套在<entry>. 我最初的尝试是这样的xml:"entry>cwe,id,attr"。
<vuln:cwe id="CWE-189" />
<entry>
xml:"entry>cwe,id,attr"
两种方法:
1/ 继续获取Token(), 直到元素具有 name cwe。 然后一个 struct "CweXml" 可以提取 id 属性:
Token()
cwe
type CweXml struct { Id string `xml:"id,attr"` }
2/ 或从 开始entry,但在这种情况下,您需要一个结构体,其中将包含CweXml结构体。
entry
CweXml
type EntryXml struct { Cwe CweXml `xml:"cwe"` }
在这种情况下,您会在entryXml.Cwe.Id.
entryXml.Cwe.Id