How to parse JSON to XML Goalng
I need to create a XML file from JSON file, if the element is empty it will not show on the XML.
But it finally return Goroutine.
How can I fix the code, thanks.
This is my expection.
This is my follow code, but I didn’t know why it cause Goroutine.
j
type CPE struct {
Deprecated bool `json:"deprecated"`
LastModified string `json:"lastModified"`
Refs []struct {
Ref string `json:"ref"`
Type string `json:"type"`
} `json:"refs"`
DeprecatedBy []struct {
CpeName string `json:"cpeName"`
CpeNameID string `json:"cpeNameId"`
} `json:"deprecatedBy"`
Deprecates []struct {
CpeName string `json:"cpeName"`
CpeNameID string `json:"cpeNameId"`
} `json:"deprecates"`
}
type CPEXmlItem struct {
XMLName xml.Name `xml:"cpe-item"`
Deprecated bool `xml:"deprecated,attr"`
Reference *struct {
Items []ItemReference `xml:"reference,omitempty"`
} `xml:"references,omitempty"`
CPE23 struct {
XMLName xml.Name `xml:"cpe-23:cpe23-item,omitempty"`
Name string `xml:"name,attr"`
Deprecation *struct {
Date string `xml:"date,attr,omitempty"`
By *struct {
Name string `xml:"name,attr,omitempty"`
Type string `xml:"type,attr,omitempty"`
} `xml:"cpe-23:deprecated-by,omitempty"`
} `xml:"cpe-23:deprecation,omitempty"`
}
}
func jsonToXml(p nvd.Product, xml *nvd.CPEXmlItem) {
if p.CPE.Deprecated {
xml.Deprecated = p.CPE.Deprecated
xml.DeprecationDate = p.CPE.LastModified
for r := range p.CPE.Refs {
ref := nvd.ItemReference{
Text: p.CPE.Refs[r].Type,
Href: p.CPE.Refs[r].Ref,
}
xml.Reference.Items = append(xml.Reference.Items, ref)
}
xml.CPE23.Deprecation.Date = p.CPE.LastModified
xml.CPE23.Deprecation.By.Name = p.CPE.DeprecatedBy[0].CpeName
}
return
}`
Read more here: Source link

