TraktorNmlUtils/models/collection/CollectionHandler.go
2024-10-11 17:48:31 +02:00

35 lines
762 B
Go

package collection
import (
"encoding/xml"
"os"
)
// ReadFileAndConvertToCollection reads a file and converts it to the Collection struct
func ReadFileAndConvertToCollection(filePath string) (*NML, error) {
// Read the file content
fileContent, err := os.ReadFile(filePath)
if err != nil {
return nil, err
}
// Unmarshal the XML content into the Collection struct
var collection NML
err = xml.Unmarshal(fileContent, &collection)
if err != nil {
return nil, err
}
return &collection, nil
}
func CollectionFromString(content string) (*NML, error) {
// Unmarshal the XML content into the Collection struct
var collection NML
err := xml.Unmarshal([]byte(content), &collection)
if err != nil {
return nil, err
}
return &collection, nil
}