Skip to content

Instantly share code, notes, and snippets.

@d-smith
Created June 1, 2015 20:10
Show Gist options
  • Save d-smith/7efc5df856f1cb933f20 to your computer and use it in GitHub Desktop.
Save d-smith/7efc5df856f1cb933f20 to your computer and use it in GitHub Desktop.
build up of soap parsing in golang
package main
import (
"encoding/xml"
"fmt"
)
var payload = `
<ns:workItem>
<typ:correspondenceCount>10</typ:correspondenceCount>
</ns:workItem>
`
type workItem struct {
CorrespondenceCount int `xml:"correspondenceCount"`
}
func main() {
var witem workItem
err := xml.Unmarshal([]byte(payload), &witem)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%v\n", witem)
}
package main
import (
"encoding/xml"
"fmt"
)
var payload = `
<ns:create>
<ns:workItem>
<typ:correspondenceCount>10</typ:correspondenceCount>
</ns:workItem>
</ns:create>
`
type create struct {
WorkItem workItem `xml:"workItem"`
}
type workItem struct {
CorrespondenceCount int `xml:"correspondenceCount"`
}
func main() {
var createRequest create
err := xml.Unmarshal([]byte(payload), &createRequest)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%v\n", createRequest.WorkItem)
}
package main
import (
"encoding/xml"
"fmt"
)
var payload = `
<soapenv:Body>
<ns:create>
<ns:workItem>
<typ:correspondenceCount>10</typ:correspondenceCount>
</ns:workItem>
</ns:create>
</soapenv:Body>
`
type createBody struct {
Create create `xml:"create"`
}
type create struct {
WorkItem workItem `xml:"workItem"`
}
type workItem struct {
CorrespondenceCount int `xml:"correspondenceCount"`
}
func main() {
var createBody createBody
err := xml.Unmarshal([]byte(payload), &createBody)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%v\n", createBody.Create.WorkItem)
}
package main
import (
"encoding/xml"
"fmt"
)
var payload = `
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://xmlns.fmr.com/systems/dev/xtrac/2004/06/" xmlns:ser="http://xmlns.fmr.com/common/headers/2005/12/ServiceProcessingDirectives" xmlns:ser1="http://xmlns.fmr.com/common/headers/2005/12/ServiceCallContext" xmlns:typ="http://xmlns.fmr.com/systems/dev/xtrac/2004/06/types">
<soapenv:Body>
<ns:create>
<ns:workItem>
<typ:correspondenceCount>10</typ:correspondenceCount>
</ns:workItem>
</ns:create>
</soapenv:Body>
</soapenv:Envelope>
`
type createEnvelope struct {
CreateBody createBody `xml:"Body"`
}
type createBody struct {
Create create `xml:"create"`
}
type create struct {
WorkItem workItem `xml:"workItem"`
}
type workItem struct {
CorrespondenceCount int `xml:"correspondenceCount"`
}
func main() {
var createEnv createEnvelope
err := xml.Unmarshal([]byte(payload), &createEnv)
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("%v\n", createEnv.CreateBody.Create.WorkItem)
}
@musale
Copy link

musale commented Mar 30, 2017

Thank you for this gist!

@MMulthaupt
Copy link

This helped a lot. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment