Skip to content

proposal: encoding/xml: Collect metadata, like order and line numbers when parsing XML #67038

@cague

Description

@cague

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions