Yes. This works for me:
procedure TForm1.Button11Click(Sender: TObject);
var
MyXMLDocument : IXMLDocument;
DocElement, FounderNode : IXMLNode;
begin
MyXMLDocument := NewXMLDocument();
MyXMLDocument.Active := True;
DocElement := MyXMLDocument.CreateElement('ab', 'MyString');
MyXMLDocument.DocumentElement := DocElement;
// alternatively:
// DocElement := MyXMLDocument.AddChild('ab', 'MyString');
DocElement.DeclareNamespace('xsi', 'https://www.guru99.com/XMLSchema-instance');
DocElement.DeclareNamespace('xsd', 'https://www.guru99.com/XMLSchema');
// if this call is present then the 'xmlns=MyString' attribute will be at the end of the element,
// but if this is omitted then the attribute will be at the front of the element instead, due to
// the earlier CreateElement/AddChild call...
DocElement.DeclareNamespace('', 'MyString');
FounderNode := DocElement.AddChild('founder');
FounderNode.Text := 'Krishna';
MyXMLDocument.SaveToFile('TestOne01.XML');
end;
It is important that the 'ab' element actually have the 'MyString' namespace assigned to it, so that any child nodes can inherit it. When an `xmlns` attribute appears on a child node, it means the namespace was not inherited correctly.