Actually, despite my comment above, I found that the easiest way to do this is not with DeclareNamespace .
Here is an example that doesn't even use TXMLDocument in the form. Just add xmldom , XMLIntf and XMLDoc to your sentence using the sentence ( Xml.xmldom , Xml.XMLIntf and Xml.XMLDoc for XE2) and then it works:
procedure TForm1.Button1Click(Sender: TObject); var TheDoc: IXmlDocument; iNode: IXmlNode; xmlText: DOMString; begin TheDoc := NewXMLDocument; TheDoc.Version := '1.0'; TheDoc.Encoding := 'UTF-16'; iNode := TheDoc.AddChild('test:test_file'); iNode.SetAttributeNS('xmlns:test', '', 'http://www.foo.com' ); iNode.SetAttributeNS('xmlns:xsi', '', 'http://www.w3.org/2001/XMLSchema'); TheDoc.SaveToXML(xmlText); Memo1.Lines.Text := xmlText; end;
The above results are output to TMemo :
<?xml version="1.0" encoding="UTF-16"?> <test:test_file xmlns:test="http://www.foo.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema"/>
source share