-
Notifications
You must be signed in to change notification settings - Fork 17.8k
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
proposal: encoding/xml: Collect metadata, like order and line numbers when parsing XML #67038
Comments
Please describe the new API you are suggesting. Thanks. |
There isn't a new API in the sense that there are new functions. There are new "field tags" for structures. xml:",order" // Stores the order of the Element within the Element's parent Element So when Go's regular Unmarshal function is used, the Go code will fill in those values. See ProblemsXML structure in the other comments to see the field tags in use. |
OK, can you write out the new documentation that would be added to the encoding/xml package? Thanks. |
This is the current doc here for Unmarshal
The new doc would add more bullet points:
And then maybe also have a field tag for catching "out of order" elements.
type OutOfOrderItems []OutOfOrderItem type OutOfOrderItem struct { This is similar to XML schema element xs:sequence and can be used to help enforce order. |
Thanks. |
Proposal Details
When parsing / Unmarshalling an XML Elements, collect order and line numbers.
Use field tags, like below:
type Vehicle struct {
Make string
xml:"make"
Model string
xml:"model"
Wheelbase float32
xml:"wheelbase"
ProblemsXML
}
type ProblemsXML struct {
XMLName Name
UnkElems []XMLElement
xml:",any"
UnkAttrs []Attr
xml:",any,attr"
Ooois OutOfOrderItems
xml:",ooorder"
Order int
xml:",order"
Line int
xml:",line"
}
Example:
line 1
line 2 Chevrolet
line 3 107.2
line 4 Corvette
line 5
line 6
line 7 Chevrolet
line 8 107.2
line 9 Corvette
line 19
Vehicle[0].Order == 1
Vehicle[0].Line == 1
Vehicle[1].Order == 2
Vehicle[1].Line == 6
I have the code, not very complicated.
Is the next step to wait for approval before a pull request?
The text was updated successfully, but these errors were encountered: