Comments (5)
Please describe the new API you are suggesting. Thanks.
from go.
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
xml:",line" // Stores the line number for the start of the 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.
from go.
OK, can you write out the new documentation that would be added to the encoding/xml package? Thanks.
from go.
This is the current doc here for Unmarshal
https://pkg.go.dev/encoding/xml#Unmarshal
There is a list of bullet points describing struct field tags.
Here's one of the existing bullet points:
- If the XML element contains a sub-element that hasn't matched any of the above rules and the struct has a field with tag ",any", unmarshal maps the sub-element to that struct field.
The new doc would add more bullet points:
- A struct field with tag ",line" contains the line number for the start Element
- A struct field with tag ",order" contains the order of the Element within the Element's parent Element
And then maybe also have a field tag for catching "out of order" elements.
- A struct field with tag ",ooorder" contains information on Elements that do not follow the order of the structure defined and passed to Unmarshal. The struct field must be of type OutOfOrderItems
type OutOfOrderItems []OutOfOrderItem
type OutOfOrderItem struct {
ElementOOO string // Out of order child element that appears after ElementMarker in the parsed XML
ElementMarker string // The element that appears before ElementOOO in the parsed XML but is defined after ElementOOO in the structure that Unmarshal stores the parsed results
}
This is similar to XML schema element xs:sequence and can be used to help enforce order.
e.g.
msg = fmt.Sprintf("out of order: Element "%v" must be before Element "%v"", oooi.ElementOOO , oooi.ElementMarker)
from go.
Thanks.
from go.
Related Issues (20)
- os: Wait can wait on the wrong process
- proposal: strings: add a ReplaceRange function HOT 9
- x/tools/go/packages: pass overlay to all invocations of `go list`
- x/tools/gopls: Cannot navigate to function on MacOS when the go file is Windows OS specific.
- os/exec: Cmd.Wait Cmd.StderrPipe data-loss race condition go1.22.3 240525 darwin-arm64 14.5 HOT 4
- runtime: SIGSEGV after performing clone(CLONE_PARENT) via C constructor prior to runtime start [1.22 backport] HOT 1
- syscall: Setuid undefined on aix HOT 1
- cmd/link/internal/ld: TestElfBindNow/bindnow-pie-linkmode-external failures HOT 1
- runtime/cgo: cgo can't work with some old versions glibc HOT 2
- make.bash: ~/go1.4/bin/go: no such file or directory after CL 582076 HOT 3
- net/http: infinite redirect on path variable followed by trailing slash
- x/tools/gopls: export LSP types so they can be imported by external consumers HOT 2
- x/website: add more detail about GOPATH and where to clone src code in contribution guide
- cmd/go: for every test run in go/testdata/script results in windows command prompt rapidly opens and closes HOT 2
- cmd/go: internal compiler error: assertion failed: on source consisting of {panic, declaration, label} HOT 2
- math: math.Mod(Exp(63.5)*10000.0, 100.0) return different values between C exp() HOT 1
- x/tools/gopls: add control flow token support HOT 2
- x/net/http2: requests experience excessive time delays when encountering network errors HOT 1
- net/http: Inconsistent output with req.URL.RequestURI() HOT 1
- x/tools/gopls: failed to install gopls@latest with VSCode extension and Go 1.18 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from go.