Created
June 1, 2015 20:10
-
-
Save d-smith/7efc5df856f1cb933f20 to your computer and use it in GitHub Desktop.
build up of soap parsing in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thank you for this gist!