gazebosim / sdformat

Simulation Description Format (SDFormat) parser and description files.
http://sdformat.org
Apache License 2.0
166 stars 92 forks source link

ToElement methods do not export data from custom xml namespaces #1261

Open scpeters opened 1 year ago

scpeters commented 1 year ago

Environment

Description

Steps to reproduce

  1. TODO: write code to reproduce this

Output

azeey commented 1 year ago

I think Root::Element() would work though and maybe ToElement should check if the DOM object was loaded from XML (i.e, has a valid Element()) and return that.

scpeters commented 1 year ago

I think Root::Element() would work though and maybe ToElement should check if the DOM object was loaded from XML (i.e, has a valid Element()) and return that.

but if you make changes via the DOM API, will those be reflected in the Element() output?

azeey commented 1 year ago

but if you make changes via the DOM API, will those be reflected in the Element() output?

They would not. I guess if we want that we'd have to store the custom elements and attributes somehow and incorporate them into the output of ToElement. It wouldn't be trivial though since each element of the DOM object might have a custom attribute or custom element.

scpeters commented 1 year ago

but if you make changes via the DOM API, will those be reflected in the Element() output?

They would not. I guess if we want that we'd have to store the custom elements and attributes somehow and incorporate them into the output of ToElement. It wouldn't be trivial though since each element of the DOM object might have a custom attribute or custom element.

One approach would be to add CustomData class to the SDFormat c++ classes that stores a Param_V of custom attributes and an ElementPtr_V of custom child elements and populates it during parsing. Drawbacks:

scpeters commented 5 months ago

Based on this portion of Plugin_TEST.cc, I believe that data from custom XML namespaces in the Plugin::Contents (child elements of <plugin/>) will be correctly exported by Plugin::ToElement. Exporting custom attributes of <plugin/> is not currently supported. In order to export custom attributes from a <plugin/> element for use in gz-sim, in addition to modifying the sdf::Plugin constructor in sdf/Plugin.hh, the corresponding gz/msgs/plugin.proto message file would need to be updated as well.