refactor func parseXML

This commit is contained in:
Christoph Polcin
2014-10-23 11:29:26 +02:00
parent 46bd8fb68a
commit 542e8e73bc
2 changed files with 17 additions and 12 deletions

View File

@@ -2,6 +2,7 @@ package gowebdav
import (
"bytes"
"encoding/xml"
"io"
"strconv"
"strings"
@@ -31,3 +32,17 @@ func parseModified(s *string) time.Time {
}
return time.Unix(0, 0)
}
func parseXML(data io.Reader, resp interface{}, parse func(resp interface{})) {
decoder := xml.NewDecoder(data)
for t, _ := decoder.Token(); t != nil; t, _ = decoder.Token() {
switch se := t.(type) {
case xml.StartElement:
if se.Name.Local == "response" {
if e := decoder.DecodeElement(resp, &se); e == nil {
parse(resp)
}
}
}
}
}