gazebosim / gazebosim/sdformat
`ToString` doesn't skip default elements and attributes on `sdf::ElementPtr` returned from `ToElement`
- Dominant language
- C++
- Stars
- 216
- Forks
- 125
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 14
Description
## Environment
* OS Version: any
* Source or binary build? `sdf12`
## Description
When using `sdf::Element::ToString`, libsdformat currently checks to see if an element or attribute is set by the user and skips printing it if it's not. This helps avoid verbose SDFormat files with elements and attributes having default values. However, this behavior only works if the `sdf::ElementPtr` was obtained from loading a file/string via `sdf::readFile`/`sdf::readString` or calling the `Element` function on DOM objects (e.g., `sdf::Model::Element`). It does not work if the `sdf::ElementPtr` is obtained form calling the `ToElement` function on DOM objects (e.g., `sdf::Model::ToElement`).
Example:
```xml
```
Using `model->Element()->ToString("")`
```xml
```
Using `model->ToElement()->ToString("")`
```xml
false
false
true
false
0 0 0 0 -0 0
0 0 0 0 -0 0
0 0 0 0 -0 0
1
1
0
0
1
0
1
false
```
Relates to : https://github.com/ignitionrobotics/sdformat/pull/575, https://github.com/ignitionrobotics/sdformat/pull/842
Contributor guide
Research direction
Start with sdf::Element::ToString and compare the behavior of elements returned by Element() with those returned by DOM ToElement(). Trace how readFile/readString and the DOM conversion mark user-set elements and attributes. Done means ToElement()-derived elements also omit unset default values and attributes, matching the existing concise output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100