gnewton / chidley

Convert XML to Go structs / XML to JSON
Apache License 2.0
274 stars 35 forks source link

Not handling XML namespaces correctly, creating incorrect Go identifiers for variable names #25

Closed gnewton closed 6 years ago

gnewton commented 6 years ago

When xml like this is encountered: <credit-words default-x="1124" default-y="1393" font-size="12" font-weight="bold" halign="right" justify="center" valign="top" xml:space="preserve">Words and Music by J.Bach</credit-words>

The "xml:" in xml:space refers to a name space which is: http://www.w3.org/XML/1998/namespace

However, chidley does not handle this properly, creating in a referencing struct:

AttrHttp://www.w3.org/XML/1998/namespaceSpace string `xml:"http://www.w3.org/XML/1998/namespace space,attr"`

Which does not compile due to the ': / .' characters in the variable name.

Instead, it should replace these characters in some canonical (if perhaps ugly) way, such as: AttrHttp_colonslashslash_www_dot_w3_dot_org_slash_XML_slash_1998_slash_namespaceSpace xml:"http://www.w3.org/XML/1998/namespace space,attr"

Ugly like this to avoid accidental name clashes.

gnewton commented 6 years ago

Fixed. Now generates compiling code with correct - if ugly - variable names. As per above suggested format.