-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheader_extractor.go
56 lines (45 loc) · 1.1 KB
/
header_extractor.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"encoding/xml"
"log"
"os"
)
// Struct definitions
type LandingPageSet struct {
LandingPage LandingPage `xml:"LANDING_PAGE"`
}
type LandingPage struct {
Attributes Attributes `xml:"ATTRIBUTES"`
}
type Attributes struct {
StringAttributes []StringAttribute `xml:"STRING_ATTRIBUTE"`
}
type StringAttribute struct {
Tag string `xml:"TAG"`
Value string `xml:"VALUE"`
}
func getHeaderValueFromXMLContent(xmlContent []byte) (string, string, error) {
var landingPageSet LandingPageSet
err := xml.Unmarshal(xmlContent, &landingPageSet)
if err != nil {
log.Fatal("Unmarshalling XML file failed", err)
}
var header, doi string
// Iterate over the string attributes to find the header and doi values
for _, attr := range landingPageSet.LandingPage.Attributes.StringAttributes {
switch attr.Tag {
case "header":
header = attr.Value
case "doi":
doi = attr.Value
}
}
if header == "" {
return "", "", err
}
return header, doi, nil
}
// Function to read the XML file and return its content
func readXMLFile(filePath string) ([]byte, error) {
return os.ReadFile(filePath)
}