XML to GO
JSON에 비해 XML의 경우 좀더 파싱이 복잡한 편이긴 합니다만. Go에서는 XML의 Marshal, Unmarshal도 지원을 하고 있습니다. 앞서 작성한 JSON to GO와 마찬가지로 XML의 경우도 구조체를 통해 처리하는 것이 여러모로 관리가 편합니다.
이 사이트를 이용하시면 매우 편리하구요 ㅎㅎ
XML
<breakfast_menu>
<food>
<name>Belgian Waffles</name>
<price>$5.95</price>
<description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>
<calories>650</calories>
</food>
<food>
<name>Strawberry Belgian Waffles</name>
<price>$7.95</price>
<description>Light Belgian waffles covered with strawberries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>Berry-Berry Belgian Waffles</name>
<price>$8.95</price>
<description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>
<calories>900</calories>
</food>
<food>
<name>French Toast</name>
<price>$4.50</price>
<description>Thick slices made from our homemade sourdough bread</description>
<calories>600</calories>
</food>
<food>
<name>Homestyle Breakfast</name>
<price>$6.95</price>
<description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>
<calories>950</calories>
</food>
</breakfast_menu>이런 XML 을 입력하면. ( 출처 : www.w3schools.com/xml/simple.xml )
Go
type BreakfastMenu struct {
XMLName xml.Name `xml:"breakfast_menu"`
Text string `xml:",chardata"`
Food []struct {
Text string `xml:",chardata"`
Name string `xml:"name"`
Price string `xml:"price"`
Description string `xml:"description"`
Calories string `xml:"calories"`
} `xml:"food"`
} 요래 이쁘장하게 struct 로 뽑아냅니다.