Delphi Examples

ChilkatHOMEASPVisual BasicVB.NETC#Visual C++CMFCDelphiFoxProJavaPerlPHPPythonRubySQL ServerVBScript

Delphi Examples

Bounced Mail
Bz2
Character Encoding
CSV
Digital Certificates
Digital Signatures
DH Key Exchange
DSA
Email
Email Object
FTP
HTML-to-XML
HTTP
IMAP
Encryption
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SFTP
SSH
SSH Key
SSH Tunnel
String
Tar
Upload
XML
XMP
Zip Compression

More Examples...
Byte Array
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate

Unreleased...
Bzip2
LZW
Icon

Type Conversion

 

Article: Understanding COM References in Delphi

Remove Nodes from an XML Document

Download Delphi Source Code and Project Files

Source Code Listing

// Delete Keyword nodes from the XML Document, and
// add them to a new document without duplicates.
procedure TForm1.Example4Click(Sender: TObject);
var
  xml: IChilkatXml;
  outXml: IChilkatXml;
  node: IChilkatXml;
  kNode: IChilkatXml;
  tempNode: IChilkatXml;
begin
    xml := CoChilkatXml.Create();
    outXml := CoChilkatXml.Create();

    // Load the input document.
    xml.LoadXmlFile('crisp.xml');

    // Create the output XML document in-memory
    outXml.Tag := 'unique_keywords';

    // Iterate over the "DOC" nodes by calling FirstChild
    // followed by NextSibling2 repeatedly until it returns false.
    node := xml.FirstChild();
    while (node <> nil) do
    begin
	    // Iterate over the Keyword nodes, remove each, and add it to
	    // our new XML document. (Note that the search happens at the
	    // subtree rooted at our current node, and not the entire XML document.)
	    kNode := node.SearchForTag(nil,'Keyword');
	    while (kNode <> nil) do
      begin
          // Does the keyword already exist in the output document?
          if (outXml.SearchForContent(nil,'keyword',kNode.Content) = nil) then
          begin
            outXml.NewChild2('keyword',kNode.Content);
          end;

          tempNode := kNode;
          kNode := node.SearchForTag(kNode,'Keyword');

	        // Remove the keyword that was just processed from the XML document.
	        tempNode.RemoveFromTree();
      end;

	    // Move to the next sibling. The internal reference within node is updated
	    // to the node's next sibling. If no siblings remain, it returns 0.
	    if (node.NextSibling2() = 0) then
        node := nil;
    end;

    // Sort the output by content.
    outXml.SortByContent(1);

    // Save the unique keywords.
    outXml.SaveXml('UniqueKeywords.xml');

    // Save the original document with all the keywords removed.
    xml.SaveXml('KeywordsRemoved.xml');

end;



 

Need a specific example? Send a request to support@chilkatsoft.com

© 2000-2008 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Email Component · XML Parser