New xml format (#7947)

# Description

Changes old `from xml` `to xml` data formats. See #7682 for reasoning
behind this change.
Output is now a series of records with `tag`, `attributes` and `content`
fields.

Old:

![image](https://user-images.githubusercontent.com/17511668/224508728-92d37c1f-ebac-4d5c-924d-bebd60f5cf85.png)
New:

![image](https://user-images.githubusercontent.com/17511668/224508753-a2de338a-ff2a-41e0-bbc1-ccc07a1d00ce.png)


# User-Facing Changes

New output/input format, better error handling for `from xml` and `to
xml` commands.

# Tests + Formatting

Don't forget to add tests that cover your changes.

Make sure you've run and fixed any issues with these commands:

- `cargo fmt --all -- --check` to check standard code formatting (`cargo
fmt --all` applies these changes)
- `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A
clippy::needless_collect` to check that you're using the standard code
style
- `cargo test --workspace` to check that all tests pass

# After Submitting

If your PR had any user-facing changes, update [the
documentation](https://github.com/nushell/nushell.github.io) after the
PR is merged, if necessary. This will help us keep the docs up to date.
This commit is contained in:
Artemiy
2023-03-12 02:35:42 +03:00
committed by GitHub
parent 2e01bf9cba
commit a13946e3ef
6 changed files with 663 additions and 301 deletions

View File

@ -179,7 +179,18 @@ fn parses_json() {
fn parses_xml() {
let actual = nu!(
cwd: "tests/fixtures/formats",
"open jonathan.xml | get rss.children.channel.children | get 0.3.item.children | get 3.link.children.0"
pipeline(r#"
open jonathan.xml
| get content
| where tag == channel
| get content
| flatten
| where tag == item
| get content
| flatten
| where tag == guid
| get content.0.content.0
"#)
);
assert_eq!(

View File

@ -8,7 +8,15 @@ fn table_to_xml_text_and_from_xml_text_back_into_table() {
open jonathan.xml
| to xml
| from xml
| get rss.children.channel.children.0.3.item.children.guid.4.attributes.isPermaLink
| get content
| where tag == channel
| get content
| flatten
| where tag == item
| get content
| flatten
| where tag == guid
| get 0.attributes.isPermaLink
"#
));