Skip to content
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

preserve node prefix #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,13 @@ fn convert_node(el: &Element, config: &Config, path: &String) -> Option<Value> {
for child in el.children() {
match convert_node(child, config, &path) {
Some(val) => {
let name = &child.name().to_string();
let name = if child.prefix().is_some() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels awkward. There is probably a more idiomatic way of achieving the same.

let formatted_name = format!("{}:{}", child.prefix().unwrap(), child.name().to_string());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

format!() macro is a slow way of string concatenation. Consider [].concat()

formatted_name
} else {
child.name().to_string()
};
let name = &name;

#[cfg(feature = "json_types")]
let path = [path.clone(), "/".to_owned(), name.clone()].concat();
Expand Down Expand Up @@ -428,8 +434,14 @@ fn convert_node(el: &Element, config: &Config, path: &String) -> Option<Value> {

fn xml_to_map(e: &Element, config: &Config) -> Value {
let mut data = Map::new();
let name = if e.prefix().is_some() {
let formatted_name = format!("{}:{}", e.prefix().unwrap(), e.name().to_string());
formatted_name
} else {
e.name().to_string()
};
data.insert(
e.name().to_string(),
name,
convert_node(&e, &config, &String::new()).unwrap_or(Value::Null),
);
Value::Object(data)
Expand Down