On Wed, 28 Oct 2015 08:39:57 -0700 (PDT)
Tong Sun <
sunto...@gmail.com> wrote:
[...]
> For condition, for e.g., the only thing I care about is
> `xml:"ConditionalRule>RuleParameters>RuleParameter"`, however, if I
> process it like this --
>
https://play.golang.org/p/ryq3l3MKwy
>
> Then all the webtest requests buried beneath the condition tag will
> be eaten, by the `xml.Unmarshal` I think, so all "interesting" stuff
> would be gone.
>
> I need a event driven base XML parsing approach so that, when seeing
> the interesting XML starting tag, **regardless where they are**,
> process my interested tags, without side-effects like eating up
> sub-xmls, or being ignored because of they are under certain tags.
> How is that possible?
The xml.Decoder of the encoding/xml package supports mixed-mode
decoding, where you iterate over the XML document using the decoder's
RawToken() method until you find an "interesting" start element,
and once such found, you can use the decoder's DecodeElement() method
to get the same effect as you would call Unmarshal() on exactly that
part of the XML document's tree your start element points at.