@@ -309,6 +309,8 @@ void BT::XMLParser::PImpl::loadSubtreeModel(const XMLElement* xml_root)
309309 {
310310 throw RuntimeError (" Missing attribute [name] in port (SubTree model)" );
311311 }
312+ // Validate port name
313+ validatePortName (name, port_node->GetLineNum ());
312314 if (auto default_value = port_node->Attribute (" default" ))
313315 {
314316 port.setDefaultValue (default_value);
@@ -550,6 +552,11 @@ void VerifyXML(const std::string& xml_text,
550552 {
551553 ThrowError (line_number, " The tag <BehaviorTree> must have the attribute [ID]" );
552554 }
555+ // Validate BehaviorTree ID as a model name
556+ if (!ID .empty ())
557+ {
558+ validateModelName (ID , line_number);
559+ }
553560 if (registered_nodes.count (ID ) != 0 )
554561 {
555562 ThrowError (line_number, " The attribute [ID] of tag <BehaviorTree> must not use "
@@ -568,6 +575,8 @@ void VerifyXML(const std::string& xml_text,
568575 ThrowError (line_number,
569576 " <SubTree> with ID '" + ID + " ' should not have any child" );
570577 }
578+ // Validate SubTree ID as a model name
579+ validateModelName (ID , line_number);
571580 if (registered_nodes.count (ID ) != 0 )
572581 {
573582 ThrowError (line_number, " The attribute [ID] of tag <SubTree> must not use the "
@@ -578,6 +587,11 @@ void VerifyXML(const std::string& xml_text,
578587 {
579588 // use ID for builtin node types, otherwise use the element name
580589 const auto lookup_name = is_builtin ? ID : name;
590+ // Validate model name for custom node types (non-builtin element names)
591+ if (!is_builtin)
592+ {
593+ validateModelName (name, line_number);
594+ }
581595 const auto search = registered_nodes.find (lookup_name);
582596 const bool found = (search != registered_nodes.end ());
583597 if (!found)
@@ -743,6 +757,12 @@ TreeNode::Ptr XMLParser::PImpl::createNodeFromXML(const XMLElement* element,
743757 const char * attr_name = element->Attribute (" name" );
744758 const std::string instance_name = (attr_name != nullptr ) ? attr_name : type_ID;
745759
760+ // Validate instance name if explicitly provided
761+ if (attr_name != nullptr )
762+ {
763+ validateInstanceName (instance_name, element->GetLineNum ());
764+ }
765+
746766 const TreeNodeManifest* manifest = nullptr ;
747767
748768 auto manifest_it = factory->manifests ().find (type_ID);
0 commit comments