summaryrefslogtreecommitdiff
path: root/gohadoopxml.go
blob: d6d5721ee124824438764c583bf74c84047037d9 (plain)
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
package gohadoopxml

import (
	"encoding/xml"
	"io/ioutil"
	"log"
	"os"
)

var Version string

type Property struct {
	XMLName xml.Name `xml:"property"`
	Name    string   `xml:"name"`
	Value   string   `xml:"value"`
}

type Configuration struct {
	XMLName    xml.Name   `xml:"configuration"`
	Properties []Property `xml:"property"`
}

func ParseXML(filename string) (Configuration, error) {
	xmlFile, err := os.Open(filename)
	if err != nil {
		log.Println("Error occurred while opening xml file")
		return Configuration{}, err
	}
	defer xmlFile.Close()

	xmlData, _ := ioutil.ReadAll(xmlFile)

	var config Configuration
	xml.Unmarshal(xmlData, &config)

	return config, nil
}

func MergeConfigurations(configs ...Configuration) Configuration {
	var new_config Configuration
	for _, config := range configs {
		new_config.Properties = append(new_config.Properties,
			config.Properties...)
	}
	return new_config
}