TXMLDocumentResync (Delphi)
Description
The following example uses the Resync function.
Code
procedure Test_Resync;
var
LDocument: IXMLDocument;
LCount: Integer;
begin
LDocument := TXMLDocument.Create(nil);
LDocument.LoadFromXML('<TestElement><!-- TestComment --></TestElement>');
{ Cache the document element ChildNodes.Count property.
Otherwise resync is unnecessary. }
LCount := LDocument.DocumentElement.childNodes.Count;
{ Modify the document element child nodes through the DOM interface. }
LDocument.DocumentElement.DOMNode.appendChild
(LDocument.DOMDocument.createCDATASection('test node'));
{ The two child lists are now different. }
Writeln('LDocument.DocumentElement.ChildNodes.Count: ' +
IntToStr(LDocument.DocumentElement.childNodes.Count));
Writeln('LDocument.DocumentElement.DOMNode.childNodes.length: ' +
IntToStr(LDocument.DocumentElement.DOMNode.childNodes.length));
LDocument.Resync;
Writeln(sLineBreak + 'After resync...' + sLineBreak);
{ The two child lists are now synchronized. }
Writeln('LDocument.DocumentElement.ChildNodes.Count: ' +
IntToStr(LDocument.DocumentElement.childNodes.Count));
Writeln('LDocument.DocumentElement.DOMNode.childNodes.length: ' +
IntToStr(LDocument.DocumentElement.DOMNode.childNodes.length));
end;
Uses
- Xml.XMLDoc.TXMLDocument.LoadFromXML ( fr | de | ja )
- Xml.XMLDoc.TXMLDocument.DOMDocument ( fr | de | ja )
- Xml.XMLDoc.TXMLDocument.Resync ( fr | de | ja )