summaryrefslogtreecommitdiff
path: root/xml.go
diff options
context:
space:
mode:
Diffstat (limited to 'xml.go')
-rw-r--r--xml.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/xml.go b/xml.go
new file mode 100644
index 0000000..3471bba
--- /dev/null
+++ b/xml.go
@@ -0,0 +1,47 @@
+package main
+
+import (
+ "encoding/xml"
+ "fmt"
+ "net/url"
+)
+
+type XMLURLset struct {
+ XMLName xml.Name `xml:"urlset"`
+ Xmlns string `xml:"xmlns,attr"`
+ URLs []URL `xml:"url"`
+}
+
+type URL struct {
+ Loc Loc `xml:"loc"`
+}
+
+type Loc struct {
+ Text string `xml:",chardata"`
+}
+
+func toSitemap(seen map[url.URL]int) (string, error) {
+ var xmlURLs []URL
+
+ for u := range seen {
+ xmlURL := URL{
+ Loc: Loc{
+ Text: fmt.Sprintf("%s", &u),
+ },
+ }
+
+ xmlURLs = append(xmlURLs, xmlURL)
+ }
+
+ set := XMLURLset{
+ Xmlns: "http://www.sitemaps.org/schemas/sitemap/0.9",
+ URLs: xmlURLs,
+ }
+
+ output, err := xml.MarshalIndent(&set, "", "\t")
+ if err != nil {
+ return "", err
+ }
+
+ return string(output), nil
+}