On Friday, 6 January 2017 13:28:22 UTC+2, John Leidegren wrote: > > So after talking a look at the xml package again I noticed the > UnmarshalXML trap. So I used that. Here's the solution I went with. > > I wrapped the decoder in a recursive decent parser to make the actual > UnmarshalXML method readable. > > https://play.golang.org/p/dylYB0KsyL > > It uses an example from the OpenGL registry where you can see that > parameters use mixed content. They annotate the base type "ptype" and > "name" but the rest is left as text (or so called chardata). >
You can also use the "lazy-mans-version" https://play.golang.org/p/WkR86QrEyK. (Of course only designed to work on this exact data) + Egon > John > > On Friday, January 6, 2017 at 11:01:12 AM UTC+1, Egon wrote: >> >> You can use xml.Decoder (https://play.golang.org/p/fkp-t4_vee). >> >> Can you show in which place OpenGL registry contains such entries? Just >> interested in why it is encoded that way. >> >> Also take a look at https://github.com/go-gl/glow >> >> + Egon >> >> On Friday, 6 January 2017 11:28:42 UTC+2, John Leidegren wrote: >>> >>> OK, then I give up. If that is how it works. >>> >>> The source XML file I'm reading is from the OpenGL registry and I cannot >>> change the way they structured that file. What baffles me is that I can't >>> seem to simply concat the text nodes either. >>> >>> I'd like to, as an option, just read the the concatenated text nodes >>> from a sub tree as chardata but it appears as if it just ignores >>> descendants. >>> >>> I'll fallback to innerxml and parse that manually, which is a little >>> painful to have to do but doable. >>> >>> John >>> >>> On Thursday, January 5, 2017 at 9:38:17 PM UTC+1, Shawn Milochik wrote: >>>> >>>> On Thu, Jan 5, 2017 at 2:40 PM, John Leidegren <john.le...@gmail.com> >>>> wrote: >>>> >>>>> See https://play.golang.org/p/XjKdm7Pooh >>>>> >>>>> I was hoping to get back a, b followed by c but I get a, c then b. I >>>>> just can't get this to work. >>>>> >>>>> How is it even possible for it to read character data from before and >>>>> after the B node? >>>>> >>>>> >>>> The problem is that there is no C. A gets the characters from the <el> >>>> element, and B gets the b from the <B> element: >>>> >>>> https://play.golang.org/p/czAXksSYMo >>>> >>>> I don't think you can get what you want from the XML unmarshal if 'a' >>>> and 'c' are going to be chardata in the same element. You may just have to >>>> put them in separate elements or parse the 'A' value to get the two >>>> separate strings. >>>> >>>> >>>> -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.