-
Notifications
You must be signed in to change notification settings - Fork 17.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
encoding/xml: support for collecting all attributes #3633
Comments
The type seems enough of a hint in the described case, but we should probably enforce the use of ",attr" with it, to sanitize the interaction with attributes in nested elements. We have this today, which is quite useful: Value string `xml:"sub>node" Several people asked to complement with this: Attr string `xml:"sub>node>attrname,attr" So this would be the counterpart: Attrs []xml.Attr `xml:"sub>node,attr"` And in the simple case: Attrs []xml.Attr `xml:",attr"` |
I am sad to say it, but I think we will have to postpone XML work until after Go 1.1. I regret that we didn't have more time to make encoding/xml better, but given the tradeoff I think focusing on core performance and implementation pieces for this final release push is probably the right choice. Unlike most of the performance and other stuff we're trying to shake out right now, functionality such as XML parsing can be provided by go get-able libraries as a stopgap until Go 1.2. Labels changed: added go1.2, removed go1.1. Owner changed to ---. |
Let say you have some XML like that: <FileRef> <Name Value="my-doc.pdf" /> </FileRef> To extract the value info I have to create 2 structure types: type FooFile struct { Filename AttrValue `xml:"FileRef>Name"` } // Wrapper structure used to extract XML node value attributes (string). type AttrValue struct { Value string `xml:",attr"` } And once I unmarshal my XML and get an object of type FooFile, I need to call file.Filename.Value() Being able to use `xml:"FileRef>Name,Value"` would be nice for sure. I personally don't find that the > are confusing. Not sure how the new custom unmarshelers will work tho. |
+1 for having support for unmarshalling attributes of a specific node without having to replicate the entire struct hierarchy. |
I still vote for this. Too bad its not a priority for you folks, looks like I'm gonna roll my own. |
up.. I need this feature |
A feature like this would make some xml encodings much more concise. For example, it would simplify item handling in MRSS from this:
Into this:
|
I've started to port my Ruby EPUB tool to Go and I'm having trouble with gathering up the book [OPF] Metadata due to there being an arbitrary number/type of nodes, with an arbitrary number/type of attributes. So being able to use Here's an example of the kind of data that needs parsing:
|
If anyone needs a generic solution to collecting an array of attributes, this is what I use currently:
It would be nice to have this support built in. |
Are you accepting contributions for:
If so, I would happily make the change. |
CL https://golang.org/cl/16292 mentions this issue. |
I came up with some kind of working code for @Zilog8's example in Code diff gist: https://gist.github.com/ivankravchenko/036f68e671e33179b636bd58f6ebc9d0 |
CL https://golang.org/cl/30946 mentions this issue. |
https://golang.org/doc/go1.8 - |
The text was updated successfully, but these errors were encountered: