可以讓DOM實現創建IDOMDocumentType
一個實例,你可以創建文檔時使用:
program test;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils,
Xml.adomxmldom,
Xml.XmlDom,
Xml.XmlDoc;
procedure Main;
var
DomImpl: IDOMImplementation;
Doc: TXMLDocument;
begin
DomImpl := GetDOM(sAdom4XmlVendor);
Doc := TXMLDocument.Create(nil);
try
Doc.DOMVendor := GetDOMVendor(sAdom4XmlVendor);
Doc.DOMDocument := DomImpl.createDocument('http://www.w3.org/2000/svg', 'svg:svg',
DomImpl.createDocumentType('svg:svg', '-//W3C//DTD SVG 1.1//EN',
'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'));
Doc.SaveToFile(ChangeFileExt(ParamStr(0), '.xml'));
finally
Doc.Free;
end;
end;
begin
try
Main;
except
on E: Exception do
begin
ExitCode := 1;
Writeln(Format('[%s] %s', [E.ClassName, E.Message]));
end;
end;
end.
上面的代碼產生以下輸出:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE svg:svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd" >
<svg:svg/>