Answer the question
In order to leave comments, you need to log in
How to make an import.xml file parser?
There is a file called import.xml. The file is located on the server where the site is located. There is a code that parses an external resource file. Question: How to parse a file that is on the server?
Here is the code to parse the file by reference.
func DownloadAzertiFile(url string) *AzertiCatalog {
list := AzertiCatalog{}
response, err := http.Get(url)
if err != nil {
return &list
} else {
defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body)
if err != nil {
return &list
}
newbody := strings.Replace(string(body), "<offers>", "", -1)
newbody = strings.Replace(newbody, "</offers>", "", -1)
err := xml.Unmarshal([]byte(newbody), &list)
if err != nil {
return &list
}
}
return &list
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question