'In Go, how to parse XML with mixed elements/chardata/elements/chardata content?
Let's say I have a structure, that can reference elements multiple times:
<?xml version="1.0" encoding="UTF-8"?>
<book category="cooking">
<title lang="en">Everyday Italian</title>
<author>Giada De Laurentiis</author>
<year>2005</year>
<price>30.00</price>
Blah Blah Blah Bleh Blah of <year/> written by <author/>
</book>
How can I parse this XML (or better to say, how can I describe the structure), so that I can have these internal references to it?
type Book struct{
t string `xml:"book>title"`
p string `xml:"book>price"`
y string `xml:"book>year"`
a string `xml:"book>author"`
blah string ???????
}
The naïve approach (https://go.dev/play/p/JVM98pCcI0D), just to describe blah as cdata is obviously wrong, because the references <year/> and <author/> are getting lost.
What is the right way to define blah here, so that the internal structure of it, is still available after parsing?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
