Einzelnen Beitrag anzeigen

Benutzerbild von Bummi
Bummi

Registriert seit: 15. Jun 2010
Ort: Augsburg Bayern Süddeutschland
3.470 Beiträge
 
Delphi XE3 Enterprise
 
#5

AW: MS One Note dateien lesen

  Alt 10. Apr 2013, 12:16
Ich habe hier einen Fetzen von einem Experiment herumliegen, vielleicht kannst Du damit was anfangen,

Delphi-Quellcode:
unit Unit5;
// TEST 20100802 Thomas Wassermann
interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, xmldom, XMLIntf, msxmldom, XMLDoc, ComCtrls,OneNote12_TLB,clipbrd;

type
  TGuidClass=Class(TComponent)
    public
    Guid:WideString;
    IsPage:Boolean;
  End;

  TForm5 = class(TForm)
    Button1: TButton;
    XMLDocument1: TXMLDocument;
    TreeView1: TTreeView;
    Button2: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TreeView1DblClick(Sender: TObject);
  private
     o:TOneNote2007;
    procedure XML2Tree(tree: TTreeView; XMLDoc: TXMLDocument);
    procedure InsertChildren(tree:TTreeview;n: TTreenode; const Guid: WideString);
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}


Function SaveStr(v:Variant):String;
begin
  if not VarIsNull(v) then Result := v else Result := '';

end;

procedure TForm5.InsertChildren(tree:TTreeview;n:TTreenode;const Guid:WideString);
var
 Resp:WideString;
 XD:TXMLDocument;
 iNode: IXMLNode;
 g : TGuidClass;
 TreeNode:TTreenode;
begin
        XD:=TXMLDocument.Create(self);
        try
          o.GetHierarchy(Guid ,hsPages,Resp);
          XD.XML.Text := resp;
          XD.Active:=true;
             if XD.DocumentElement.ChildNodes.Count > 0 then
                begin
                  iNode := XD.DocumentElement.ChildNodes[0];
                  while iNode <> nil do
                  begin
                    g := TGuidClass.Create(n.TreeView);
                    g.Guid := iNode.Attributes['ID'];
                    g.IsPage := iNode.NodeName='one:Page';
                    TreeNode := tree.Items.AddchildObject(n, SaveStr(iNode.Attributes['name']) + ' - ' + SaveStr(iNode.Attributes['path']),g);
                    InsertChildren(tree,TreeNode,g.Guid);

                    iNode := iNode.NextSibling;
                  end;
                end;
        finally
          XD.Free
        end;
end;

procedure TForm5.XML2Tree(tree: TTreeView; XMLDoc: TXMLDocument);
var
  iNode: IXMLNode;

  procedure ProcessNode(Node: IXMLNode; TreeNode: TTreeNode);
  var
    cNode: IXMLNode;
    g:TGuidClass;
    Resp:WideString;
  begin
    if Node = nil then Exit; // Aufhören, wenn ein Blatt erreicht ist

    // Einen Knoten zum Baum hinzufügen

        g := TGuidClass.Create(tree);
        g.Guid := Node.Attributes['ID'];
        g.IsPage := false;
        TreeNode := tree.Items.AddchildObject(TreeNode, SaveStr(Node.Attributes['name']) + ' - ' + SaveStr(Node.Attributes['path']),g);
        InsertChildren(tree,TreeNode,g.Guid);



    // Zum Kindknoten weiter gehen
    cNode := Node.ChildNodes.First;

    // Alle Kindknoten bearbeiten
    {
    while cNode <> nil do
    begin
      ProcessNode(cNode, TreeNode);
      cNode := cNode.NextSibling;
    end;
    }

  end;

begin
  iNode := XMLDoc.DocumentElement.ChildNodes[0];
  while iNode <> nil do
  begin
    ProcessNode(iNode, nil); // Rekursiv
    iNode := iNode.NextSibling;
  end;
end;

procedure TForm5.Button1Click(Sender: TObject);
var

 Resp:WideString;

  n: Integer;
  ID, Tag: IDOMNode;
  Tags: IDOMNodeList;
begin

   o:=TOneNote2007.Create(Self);
   o.Connect;
   o.GetHierarchy('' ,hsNotebooks,Resp);
   XMLDocument1.XML.Text := resp;
   XMLDocument1.Active:=true;

   XML2Tree(Treeview1,XMLDocument1);
  // Showmessage(Resp);
end;

procedure TForm5.FormCreate(Sender: TObject);
begin
  ReportMemoryLeaksOnShutDown := true;
end;

procedure TForm5.TreeView1DblClick(Sender: TObject);
var
 g:String;
 Resp:WideString;
 sl:TStringList;
begin
  g := TGuidClass( Treeview1.Selected.Data).Guid;
  if TGuidClass( Treeview1.Selected.Data).isPage then
      begin
// o.GetHierarchy(g ,hsPages,Resp);
        o.GetPageContent(g,Resp,piAll);
        Showmessage(Resp);
        sl := TStringList.Create;
        sl.Text := Resp;
        sl.SaveToFile('C:\temp\Seite.xml');
        sl.Free;
      end;
end;

end.
Thomas Wassermann H₂♂
Das Problem steckt meistens zwischen den Ohren
DRY DRY KISS
H₂ (wenn bei meinen Snipplets nichts anderes angegeben ist Lizenz: WTFPL)
  Mit Zitat antworten Zitat