-
Notifications
You must be signed in to change notification settings - Fork 24
⭐ parse.xml #5423
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
base: main
Are you sure you want to change the base?
⭐ parse.xml #5423
Conversation
Add support for parsing XML files, either by providing the file or by providing the XML contents directly. Signed-off-by: Dominik Richter <[email protected]>
Signed-off-by: Dominik Richter <[email protected]>
Signed-off-by: Dominik Richter <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if len(a) == 0 { | ||
return | ||
} | ||
x.attributes = map[string]string{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This always re-initializes the map.
x.attributes = map[string]string{} | |
if x.attributes == nil { | |
x.attributes = map[string]string{} | |
} |
child := x.children[i] | ||
data, isElem, params := child._params() | ||
|
||
// text data is added flat |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit I wonder if we should separate the text content into a slice to simplify this code, maybe adding the slice to the xmlElem
and append it in UnmarshalXML()
for the xml.CharData
case.
Add support for parsing XML files, either by providing the file or by providing the XML contents directly.
Using inline data:
Via file
example.xml
:Running this in MQL:
Since the conversion from XML to a flat (JSON-like) structure isn't standardized, we took an approach very similar to other formatters (e.g. xq, jsonformatter). This means:
<box/>
element has a flat fieldhello
aboveroot.box
is an array above@attribute
fields in the element<root>val</root>
is turned into{"root": "val"}
__text
child fieldFuture consideration are to add access to the entire XML structure, which is more complex to traverse, but may be required for some use-cases. We will also handle streaming data separately (for all of these formats)