trichview.com

trichview.support.examples




How to save several documents in one XML file


Return to index


Author

Message

Sergey Tkachenko

Posted: 02/05/2005 22:02:50


uses RichViewXML, RVXMLBase;


RichView1, RichView2 - trichviews to load/save.

RichViewXML1 - trichviewxml.

This example saves and loads two documents in 'd:\1.xml'


// Saving

procedure TForm1.Button1Click(Sender: TObject);

var

  T: TXMLTree;

  MainRoot, DocRoot: TXMLTag;

begin

  T := TXMLTree.Create(RichViewXML1.Encoding);

  try

    T.BaseFilePath := RichViewXML1.BaseFilePath;

    T.Items.AddTag(RichViewXML1.RootElement, T, T);

    MainRoot := T.Items[0];


    MainRoot.Items.AddTag('document1', T.Items[0], T);

    DocRoot := MainRoot.Items[MainRoot.Items.Count-1];

    RichViewXML1.RichView := RichView1;

    RichViewXML1.SaveToXML(DocRoot);


    MainRoot.Items.AddTag('document2', T.Items[0], T);

    DocRoot := MainRoot.Items[MainRoot.Items.Count-1];

    RichViewXML1.RichView := RichView2;

    RichViewXML1.SaveToXML(DocRoot);


    T.SaveToFile('d:\1.xml', RichViewXML1.WantTabs);

  finally

    T.Free;

  end;

end;


// Loading

procedure TForm1.Button2Click(Sender: TObject);

var

  T: TXMLTree;

  MainRoot, DocRoot: TXMLTag;

begin

  T := TXMLTree.Create(RichViewXML1.Encoding);

  try

      T.BaseFilePath := RichViewXML1.BaseFilePath;

      T.UnicodeTags.Add('utext');

      T.LoadFromFile('d:\1.xml');


      RichViewXML1.RichView := RichView1;

      MainRoot := T.Items.FindTagOfName(RichViewXML1.RootElement);

      if MainRoot<>nil then begin

        DocRoot := MainRoot.Items.FindTagOfName('document1');

        if DocRoot<>nil then

          RichViewXML1.LoadFromXML(DocRoot);


        RichViewXML1.RichView := RichView2;

        DocRoot := MainRoot.Items.FindTagOfName('document2');

        if DocRoot<>nil then

          RichViewXML1.LoadFromXML(DocRoot);

      end;

  finally

    T.Free;

  end;

  RichView1.Format;

  RichView2.Format;

end;





Powered by ABC Amber Outlook Express Converter