I am currently writing a library for the NameSilo API. I am stuck on the getPriceList api, which returns XML like this:
<namesilo>
<request>
<operation>getPrices</operation>
<ip>55.555.55.55</ip>
</request>
<reply>
<code>300</code>
<detail>success</detail>
<com>
<registration>8.99</registration>
<transfer>8.39</transfer>
<renew>8.99</renew>
</com>
<net>
<registration>9.29</registration>
<transfer>8.99</transfer>
<renew>9.29</renew>
</net>
</reply>
</namesilo>
As you can see, there is an element for each TLD. I would like to unmarshal the element name (example: com, net) into a property which is not called XMLName
(I want it to be called TLD).
After reading lines 34-39 of https://golang.org/src/encoding/xml/marshal.go, it seems like this is not possible.
I have tried the following code, but it does not work.
type APIResponse struct {
Request struct {
Operation string `xml:"operation"`
IP string `xml:"ip"`
} `xml:"request"`
}
type GetPricesResponse struct {
APIResponse
Reply []struct {
Domains []struct {
TLD xml.name
Registration string `xml:"registration"`
Transfer string `xml:"transfer"`
Renew string `xml:"renew"`
} `xml:",any"`
} `xml:"reply"`
}
Is there any way I can do this, or is it not possible to have a property name other than XMLName
for the xml element name.
UPDATE: I looked a bit more into the code, and I found this, which makes me think I cannot do this easily.