Created
August 11, 2018 03:48
-
-
Save srph/5af163c76cd14d87b98580085bcd7c10 to your computer and use it in GitHub Desktop.
Go: Decode SOAP XML
This file contains hidden or 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" | |
) | |
const data = `<?xml version="1.0" encoding="utf-8"?> | |
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> | |
<soap:Body> | |
<GetBranchesResponse xmlns="http://www.mobilegroupinc.com"> | |
<GetBranchesResult> | |
<Result>0</Result> | |
<Message>List of Branches</Message> | |
<BranchList> | |
<Branch> | |
<Branch_Key>6</Branch_Key> | |
<Branch_Name>Eastwood Cinemas</Branch_Name> | |
<Branch_Code>EWC</Branch_Code> | |
</Branch> | |
<Branch> | |
<Branch_Key>1</Branch_Key> | |
<Branch_Name>Lucky Chinatown Cinemas</Branch_Name> | |
<Branch_Code>LCT</Branch_Code> | |
</Branch> | |
<Branch> | |
<Branch_Key>4</Branch_Key> | |
<Branch_Name>Newport Cinemas</Branch_Name> | |
<Branch_Code>NPC</Branch_Code> | |
</Branch> | |
<Branch> | |
<Branch_Key>5</Branch_Key> | |
<Branch_Name>Southwoods Cinemas</Branch_Name> | |
<Branch_Code>SWC</Branch_Code> | |
</Branch> | |
<Branch> | |
<Branch_Key>2</Branch_Key> | |
<Branch_Name>Uptown Cinemas</Branch_Name> | |
<Branch_Code>UPT</Branch_Code> | |
</Branch> | |
<Branch> | |
<Branch_Key>3</Branch_Key> | |
<Branch_Name>Venice Cineplex</Branch_Name> | |
<Branch_Code>VNC</Branch_Code> | |
</Branch> | |
</BranchList> | |
</GetBranchesResult> | |
</GetBranchesResponse> | |
</soap:Body> | |
</soap:Envelope>` | |
func main() { | |
type Email struct { | |
Where string `xml:"where,attr"` | |
Addr string | |
} | |
type Address struct { | |
City, State string | |
} | |
type Result struct { | |
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Envelope"` | |
Body struct { | |
XMLName xml.Name `xml:"http://schemas.xmlsoap.org/soap/envelope/ Body"` | |
GetBranchesResponse struct { | |
XMLName xml.Name `xml:"http://www.mobilegroupinc.com GetBranchesResponse"` | |
GetBranchesResult struct { | |
BranchList []struct { | |
Key int `xml:"Branch_Key"` | |
} `xml:"BranchList"` | |
} `xml: "GetBranchesResult"` | |
} | |
} | |
} | |
v := Result{} | |
err := xml.Unmarshal([]byte(data), &v) | |
if err != nil { | |
fmt.Printf("error: %v", err) | |
return | |
} | |
fmt.Printf("XMLName: %#v\n", v) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment