-
Notifications
You must be signed in to change notification settings - Fork 18k
encoding/xml: ability to add attributes #4169
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
Labels
Milestone
Comments
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.1maybe. |
I've written a library called "xmlutil" that allows you to register types, similar to encoding/gob. So you can literally do something like this: type Envelope struct { Header Body } type Body struct { Response interface{} } Any tag (with any name) will be filled into the "Response" interface that is registered. It takes the tag name in the document and does a name lookup of the type. In that register function it allows you to add type attributes. Looks something like this: xmlutil.RegisterTypeMore(RunTransaction{}, xml.Name{}, []xml.Attr{...}); It does almost the same thing as the encoding/xml marshal/unmarshal, but doesn't support the ">" tag keyword. I found that the ">" keyword made things really complicated. Not sure if it would be useful to you guys or not. I hope to open source it soon, just have to get approval. |
This is a package I've created to makeup for missing functionality that I needed: https://github.com/webconnex/xmlutil With the opening example in the issue, I can do this: x := xmlutil.NewXmlUtil() x.RegisterNamespace("http://www.w3.org/2001/XMLSchema-instance", "xsi") x.RegisterTypeMore("", xml.Name{}, []xml.Attr{ xml.Attr{xml.Name{"xsi","type"},"xsd:string"}, }) And this causes any tags with a string value to have an attribute of xsi:type="xsd:string" I built it primarily for use with Soap. It depends on encoding/xml for reading tokens. It's a bit spartan on some of the Marshal/Unmarshal functionality in encoding/xml. Specifically it doesn't have parent tags `foo>bar`, and it doesn't have many of the modifiers (like innerxml). But it does allow you to register types, which is used with generic interfaces and allows you to add attributes. I hope to have some examples soon. The type registration is isolated in an instance of "XmlUtil". This allows you to have specific behaviors with built-in types that you might not want in other parts of your application. In my case I'm working with multiple SOAP Api's, and not all of them require/want xsi:type. Not sure if this is useful to you guys or not. If it is let me know. I haven't added any licensing yet, so let me know how it should be licensed. |
This issue was closed by revision 85f3acd. Status changed to Fixed. |
This issue was closed by revision 56ce83f. |
This issue was closed by revision 54bdfc0. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
The text was updated successfully, but these errors were encountered: