procedure SavePropertiesToXML(Filename: string; Props: TStrings);
{ 解析已有的XML文档 }
//适用于节点名称不同的情况
procedure LoadPropertiesFromXML(Filename: string; Props: TStrings);
//适用于节点相同的情况
procedure LoadFromXML(Filename: string; Props: TStrings);
end;
implementation
const
XMLTag = ''xml'';
XMLPrologAttrs = ''version="1.0" encoding="UTF-8"'';
XMLComment = '' Sample XML document with data about movies''#13 +
''and when and where they are showing''#13 +
''Developed by Keith Wood, 28 May 1999 '';
MovieWatcherTag = ''movie-watcher'';
MoviesTag = ''movies'';
MovieTag = ''movie'';
Id = ''id'';
Rating = ''rating'';
StarringTag = ''starring'';
TitleTag = ''title'';
//保存XML
procedure TDOMXMLpurser.SavePropertiesToXML(Filename: string; Props: TStrings);
var
XMLDoc: IXMLDOMDocument;
i:integer;
//----------------------------------------------------------------------------
procedure AddSimpleElement(Parent: IXMLDOMElement; Field: string;
AsCDATA: Boolean = False);
var
Internal: IXMLDOMElement;
begin
Internal := IXMLDOMElement(Parent.AppendChild(
XMLDoc.CreateElement((''Field.FieldName''))));
if AsCDATA then
Internal.AppendChild(XMLDoc.CreateCDATASection(Field))
else
Internal.AppendChild(XMLDoc.CreateTextNode(Field));
end;
procedure GenerateHeaders;
var
Title: IXMLDOMElement;
begin
XMLDoc.AppendChild(XMLDoc.CreateProcessingInstruction(XMLTag, XMLPrologAttrs));
XMLDoc.AppendChild(XMLDoc.CreateComment(XMLComment));
XMLDoc.AppendChild(XMLDoc.CreateElement(MovieWatcherTag));
Title := IXMLDOMElement(XMLDoc.DocumentElement.AppendChild(
XMLDoc.CreateElement(TitleTag)));
Title.AppendChild(XMLDoc.CreateTextNode(''焦点新闻''));
end;
procedure GenerateStars(Starring: IXMLDOMElement);
begin
AddSimpleElement(Starring, ''(StarField)'');
end;
procedure GenerateMovies(moviename:string);
var
Mov