Since the children of Child1 do not carry the same namespace, it must be undeclared and that is the reason that Child2 contains an empty (default) namespace.
This is called a namespace symbol.
xmlns = ", " ": , .
XML Namespaces 1.1 . , xmlns: p =" " , p (, , ) ,
; :
program SO20424534;
{$APPTYPE CONSOLE}
uses
ActiveX,
XMLdom,
XMLDoc,
XMLIntf,
SysUtils;
function TestXML : String;
var
RootNode,
CurNode : IXMLNODE;
Doc : IXmlDocument;
ns : String;
begin
Doc := Newxmldocument;
ns := 'apenootje';
Doc.Encoding := 'utf-8';
Doc.Options := [doNodeAutoIndent];
RootNode := Doc.AddChild('Document');
CurNode := RootNode.AddChild('Child1');
CurNode.DeclareNamespace('', ns);
CurNode := CurNode.AddChild('Child2', ns);
CurNode := CurNode.AddChild('Child3', ns);
Result := Doc.XML.Text;
end;
begin
try
CoInitialize(nil);
try
Writeln(TestXML);
finally
CoUninitialize;
end;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
Readln;
end;
:
<?xml version="1.0"?>
<Document>
<Child1 xmlns="apenootje">
<Child2>
<Child3/>
</Child2>
</Child1>
</Document>