Skip to content

Commit

Permalink
update quakeml from scml13 for fdsn-ws
Browse files Browse the repository at this point in the history
  • Loading branch information
bpeng committed May 9, 2024
1 parent bad71d0 commit ca2eb21
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions cmd/fdsn-ws/fdsn_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -502,22 +502,28 @@ func fdsnEventV1Handler(r *http.Request, h http.Header, b *bytes.Buffer) error {
}
defer rows.Close()

b.WriteString(`<?xml version="1.0" encoding="UTF-8"?>
<q:quakeml xmlns:q="http://quakeml.org/xmlns/quakeml/1.2" xmlns="http://quakeml.org/xmlns/bed/1.2">
<eventParameters publicID="smi:nz.org.geonet/NA">`)

var xml string

var hasHeader bool
for rows.Next() {
err = rows.Scan(&xml)
if err != nil {
return fdsnError{StatusError: weft.StatusError{Code: http.StatusInternalServerError, Err: err}, url: r.URL.String(), timestamp: tm}
}

b.WriteString(xml)
hasHeader = strings.HasPrefix(xml, `<?xml version="1.0" encoding="UTF-8"?>`) &&
strings.Contains(xml, `<q:quakeml xmlns:q="http://quakeml.org/xmlns/quakeml/1.2" xmlns="http://quakeml.org/xmlns/bed/1.2">`) &&
strings.Contains(xml, `<eventParameters`) &&
strings.Contains(xml, `</eventParameters>`)
strings.HasSuffix(xml, ` </q:quakeml>`)
}
if !hasHeader { //for all other xsl than sc3ml_0.13__quakeml_1.2.xsl generated quakeml
b.WriteString(`<?xml version="1.0" encoding="UTF-8"?>
<q:quakeml xmlns:q="http://quakeml.org/xmlns/quakeml/1.2" xmlns="http://quakeml.org/xmlns/bed/1.2">
<eventParameters publicID="smi:nz.org.geonet/NA">`)
}
b.WriteString(xml)
if !hasHeader {
b.WriteString(`</eventParameters></q:quakeml>`)
}

b.WriteString(`</eventParameters></q:quakeml>`)

h.Set("Content-Type", "application/xml")
} else {
Expand Down

0 comments on commit ca2eb21

Please sign in to comment.