FAQ
It says (in my copy of the documentation):

If the XML element contains a sub-element whose name matches
a struct field's XMLName tag and the struct field has no
explicit name tag as per the previous rule, unmarshal maps
the sub-element to that struct field.

OK, can someone translate this? I think I'm being confused by the idea
that a struct field
could have an XMLName tag. At best, this is an ambiguous term and I'm
beginning to run
out of options to test: none of the possibilities I could envisage actually
yielded expected
results.

To save time, this is what I'm trying to do: I need to locate all <a
href=...>...</a> elements
in conventional HTML pages as included in email messages (not even real
HTTP-served
documents, I'm trying to identify spammers from the documents they
distribute) and
extract from them the HREF attribute value and possibly the text that
describes it to the
reader. If there is a neat way to do this - I'm hoping to learn a bit more
about pkg/xml in
the process - please feel free to tell me, I'll probably figure out how it
works for myself, but
feel free to assume that I'm quite dense and explain as much as you like.

Lucio.

--

Search Discussions

  • Thomas Kappler at Oct 23, 2012 at 9:16 am
    Looking at the Unmarshal example [1], I think what is meant by "XMLName
    tag" is this line:

    XMLName xml.Name `xml:"Person"`

    The rest of the paragraph you quoted is saying that in this case,
    sub-elements of <Person> are mapped to struct fields of Result. If the
    struct and the XML structures needed to match exactly, there would have to
    be a Person struct inside Result. But we can Unmarshal the XML directly
    into a Result{} because of the XMLName line quoted above.

    Hope this helped.
    Thomas



    [1] http://golang.org/pkg/encoding/xml/#example_Unmarshal

    On Tuesday, October 23, 2012 9:58:46 AM UTC+2, Lucio wrote:

    It says (in my copy of the documentation):

    If the XML element contains a sub-element whose name matches
    a struct field's XMLName tag and the struct field has no
    explicit name tag as per the previous rule, unmarshal maps
    the sub-element to that struct field.

    OK, can someone translate this? I think I'm being confused by the idea
    that a struct field
    could have an XMLName tag. At best, this is an ambiguous term and I'm
    beginning to run
    out of options to test: none of the possibilities I could envisage
    actually yielded expected
    results.

    To save time, this is what I'm trying to do: I need to locate all <a
    href=...>...</a> elements
    in conventional HTML pages as included in email messages (not even real
    HTTP-served
    documents, I'm trying to identify spammers from the documents they
    distribute) and
    extract from them the HREF attribute value and possibly the text that
    describes it to the
    reader. If there is a neat way to do this - I'm hoping to learn a bit
    more about pkg/xml in
    the process - please feel free to tell me, I'll probably figure out how it
    works for myself, but
    feel free to assume that I'm quite dense and explain as much as you like.

    Lucio.
    --
  • Andy Balholm at Oct 23, 2012 at 4:13 pm
    If you're running at tip, it might be wiser to use the exp/html package. I
    doubt most spammers run their emails through an XHTML validator before they
    send them.

    --
  • Lucio at Oct 23, 2012 at 3:30 pm
    Thank you, that's probably the answer I was really looking for.

    Lucio.
    On Tuesday, 23 October 2012 17:14:56 UTC+2, Andy Balholm wrote:

    If you're running at tip, it might be wiser to use the exp/html package. I
    doubt most spammers run their emails through an XHTML validator before they
    send them.
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedOct 23, '12 at 7:58a
activeOct 23, '12 at 4:13p
posts4
users3
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase