Skip to content

Commit

Permalink
Allow attributes to be empty
Browse files Browse the repository at this point in the history
This allows custom attributes and unrecognized
attributes to contain empty strings by setting
required == 0 when calling Element::AddAttribute.

Fixes #725.

Signed-off-by: Steve Peters <scpeters@openrobotics.org>
  • Loading branch information
scpeters committed Apr 30, 2024
1 parent 0637c21 commit e55a9e1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/Utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ void copyChildren(ElementPtr _sdf, tinyxml2::XMLElement *_xml,
for (const tinyxml2::XMLAttribute *attribute = elemXml->FirstAttribute();
attribute; attribute = attribute->Next())
{
element->AddAttribute(attribute->Name(), "string", "", 1, "");
// Add with required == 0 to allow unrecognized attribute to be empty
element->AddAttribute(attribute->Name(), "string", "", 0, "");
element->GetAttribute(attribute->Name())->SetFromString(
attribute->Value());
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,8 @@ static bool readAttributes(tinyxml2::XMLElement *_xml, ElementPtr _sdf,
// attribute is found
if (std::strchr(attribute->Name(), ':') != nullptr)
{
_sdf->AddAttribute(attribute->Name(), "string", "", 1, "");
// Add with required == 0 to allow custom attribute to be empty
_sdf->AddAttribute(attribute->Name(), "string", "", 0, "");
_sdf->GetAttribute(attribute->Name())->SetFromString(attribute->Value());
attribute = attribute->Next();
continue;
Expand Down

0 comments on commit e55a9e1

Please sign in to comment.