Forum
Grundkurs
»Introduktion
»Snabbguide
»Komponenter
»Händelser
»Strängar
»Räkna med Delphi »Egna
typer
»Selektion
»Iteration
»Menyer
»Funktioner
»Arraystrukturer
Tips & Tricks
»Nya tips
»Blandat
»Databaser
»Filer
»Forms
»Grafik
»Internet
»Komponenter
»Matematik
»Multimedia
»Objekt/ActiveX
»Skrivare
»Strängar
»System
»Mest lästa tips
Artiklar
»Delphi och ADO
»Bygga en DLL
»Skapa en enkel rapport
»Hantera registret
»Enheter, units
»Klassen TCanvas
»Använd LookUp Controls
Nya
tips
Lägg
till tips
Delphilänkar
Gästbok
|
|
|
|
Finn matchande poster i XML
|
Kategori: Filer
Inlagt: 2005-11-25
Läst: 1441
Inlagt av: Staffan Berg
|
Beskrivning |
Denna kod loopar genom ett XML-dokument för att hitta matchande poster.
|
Kod |
// Iterate over the ArticleTitles beginning with 'M' // using FindNextRecord. Move these records from // the input XML document to the output XML document. procedure TForm1.Example6Click(Sender: TObject); var xmlDoc: IChilkatXml; outXml: IChilkatXml; rec1: IChilkatXml; rec2: IChilkatXml; begin xmlDoc := CoChilkatXml.Create(); outXml := CoChilkatXml.Create(); outXml.Tag := 'MRecords'; // Load the input document. xmlDoc.LoadXmlFile('crisp.xml'); // Find the first article beginning with M rec1 := xmlDoc.FirstChild(); // If rec1 matches, it returns itself. rec1 := rec1.FindNextRecord('ArticleTitle','M*'); while (rec1 <> nil) do begin // Continue the search with the next sibling. rec2 := rec1.NextSibling(); // This has the effect of removing the subtree rooted // at rec from xmlDoc, and adding it to outXml outXml.AddChildTree(rec1); if (rec2 <> nil) then rec1 := rec2.FindNextRecord('ArticleTitle','M*') else rec1 := nil; end; // Save the output document. outXml.SaveXml('MRecords.xml'); // The original document is now without articles // beginning with M xmlDoc.SaveXml('MissingMRecords.xml'); end; end.
|
|
|