Changeset 171
- Timestamp:
- Jan 30, 2024, 11:24:04 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/Table.pas
r170 r171 4 4 5 5 uses 6 Classes, SysUtils, Generics.Collections, ComCtrls ;6 Classes, SysUtils, Generics.Collections, ComCtrls, XMLRead, XMLWrite, DOM; 7 7 8 8 type … … 46 46 procedure SetInputMediaWiki(Text: string); 47 47 procedure SetInputJson(Text: string); 48 procedure SetInputXml(Text: string); 48 49 procedure SetInput(OutputFormat: TTableFormat; Text: string); 49 50 function GetInputFormats: TTableFormats; … … 457 458 end; 458 459 460 procedure TTable.SetInputXml(Text: string); 461 var 462 Doc: TXMLDocument; 463 TextStream: TStringStream; 464 TableNode: TDOMNode; 465 RowsNode: TDOMNode; 466 RowNode: TDOMNode; 467 CellNode: TDOMNode; 468 NewRow: TRow; 469 CellName: string; 470 ColumnIndex: Integer; 471 begin 472 Clear; 473 TextStream := TStringStream.Create(Text); 474 ReadXMLFile(Doc, TextStream); 475 TableNode := Doc.DocumentElement; 476 if Assigned(TableNode) and (TableNode.NodeName = 'table') then 477 with TableNode do begin 478 RowsNode := FindNode('rows'); 479 if Assigned(RowsNode) then begin 480 RowNode := RowsNode.FirstChild; 481 while Assigned(RowNode) and (RowNode.NodeName = 'row') do begin 482 NewRow := TRow.Create; 483 CellNode := RowNode.FirstChild; 484 while Assigned(CellNode) and (CellNode.NodeName = 'cell') do begin 485 CellName := string(TDOMElement(CellNode).GetAttribute('name')); 486 ColumnIndex := Columns.IndexOf(CellName); 487 if ColumnIndex < 0 then begin 488 Columns.Add(CellName); 489 ColumnIndex := Columns.Count - 1; 490 end; 491 492 while NewRow.Cells.Count <= ColumnIndex do 493 NewRow.Cells.Add(''); 494 NewRow.Cells[ColumnIndex] := string(CellNode.TextContent); 495 CellNode := CellNode.NextSibling; 496 end; 497 Rows.Add(NewRow); 498 RowNode := RowNode.NextSibling; 499 end; 500 end; 501 end; 502 FreeAndNil(TextStream); 503 FreeAndNil(Doc); 504 end; 505 459 506 procedure TTable.SetInput(OutputFormat: TTableFormat; Text: string); 460 507 begin … … 463 510 tfMediaWiki: SetInputMediaWiki(Text); 464 511 tfJson: SetInputJson(Text); 512 tfXml: SetInputXml(Text); 465 513 else raise Exception.Create(SUnsupportedFormat); 466 514 end; … … 469 517 function TTable.GetInputFormats: TTableFormats; 470 518 begin 471 Result := [tfCsv, tfJson, tfMediaWiki ];519 Result := [tfCsv, tfJson, tfMediaWiki, tfXml]; 472 520 end; 473 521
Note:
See TracChangeset
for help on using the changeset viewer.