ies, Movie: IXMLDOMElement;
begin
Movies := IXMLDOMElement(XMLDoc.DocumentElement.AppendChild(
XMLDoc.CreateElement(MoviesTag)));
Movie := IXMLDOMElement(Movies.AppendChild(
XMLDoc.CreateElement(MovieTag)));
Movie.SetAttribute(Id, ''123'');
Movie.SetAttribute(Rating, ''456'');
AddSimpleElement(Movie, ''789'');
AddSimpleElement(Movie, moviename);
AddSimpleElement(Movie, ''"(DirectorField)"'');
GenerateStars(IXMLDOMElement(Movie.AppendChild(
XMLDoc.CreateElement(StarringTag))));
AddSimpleElement(Movie, ''FieldByName(SynopsisField)'', True);
end;
//----------------------------------------------------------------------------
begin
try
XMLDoc := CoDOMDocument.Create;
GenerateHeaders;
i:=0;
repeat
GenerateMovies(Props.Strings[i]);
inc(i);
until i>=Props.Count;
Props.Text := XMLDoc.XML;
XMLDoc.save(Filename); //u8-dos格式
//Props.SaveToFile(Filename); //dos格式
finally
{ Release the DOM }
XMLDoc := nil;
end;
end;
//加载无重复属性的XML
procedure TDOMXMLpurser.LoadPropertiesFromXML(Filename: string; Props: TStrings);
var
XMLDoc: IXMLDOMDocument;
i: Integer;
procedure LoadSubProperties(Element: IXMLDOMNode; PropPrefix: string);
var
Index: Integer;
begin
if (Element.NodeType = NODE_TEXT) or (Element.NodeType = NODE_CDATA_SECTION) then
Props.Values[Copy(PropPrefix, 2, Length(PropPrefix) - 1)] := Element.NodeValue
else
for Index := 0 to Element.ChildNodes.Length - 1 do
LoadSubProperties(Element.ChildNodes[Index], PropPrefix + ''.'' + Element.NodeName);
end;
begin
XMLDoc := CoDOMDocument.Create;
Props.Clear;
try
if XMLDoc.Load(Filename) then
with XMLDoc.DocumentElement do
for i := 0 to ChildNodes.Length - 1 do
LoadSubProperties(ChildNodes[i], '''');
finally
XMLDoc := nil;
end;
end;
//加载XML
procedure TDOMXMLpurser.LoadFromXML(Filename: string; Props: TStrings);
var
XMLDoc: IXMLDOMDocument;
i: Integer;
procedure LoadSubPr