Page 1 of 1

[RvXML] How to save several documents in one XML file

Posted: Tue Sep 06, 2005 5:23 pm
by Sergey Tkachenko

Code: Select all

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;

Posted: Wed Sep 07, 2005 5:02 pm
by Guest
Prety :D

DonĀ“t you have a demo towork, with XML Stream and Indy?

Posted: Thu Sep 08, 2005 7:20 pm
by an aprendiz
hello, never I have worked with streams, neither with XML,
nor with components of Internet I have reviewed your demo,
How to save documents in one XML file
sergey, you can put a demo. to be able to send XML streams
using the RichViewXML component and indy IdTcpClient, IdTcpServer

So Thanks

Posted: Fri Sep 09, 2005 7:21 pm
by Sergey Tkachenko
RichViewXML can be found here: http://www.trichview.com/resources/xml

Use XML

Posted: Thu Oct 27, 2005 4:41 am
by guest
When i use the method SaveToStream from the component
RichViewXML

this are an XML File in stream format ?

or is like the methods SaveToStream, SaveSelecctionToStream.?

or is better use the method SaveRVFToStream?
because i want send rich text using indy.
the text most be retain attributes like font color, font, size. etc

Posted: Thu Oct 27, 2005 9:23 am
by Sergey Tkachenko
RVXML.SaveToStream saves absolutely the same information in stream as RVXML.SaveToFile saves to file.

As for XML vs RVF... Generally, RichViewXML's XML and RVF data contain the same information. XML has an advantage that it can be understanded by human, RVF is a computer-oriented format and may contain binary data (if rvfoSaveBinary is excluded from RVFOptions, binary data are saved as hexadecimal numbers, so it still cannot be read by humans). Binary RVF files are usually smaller than the corresponding XML, non-binary may be larger in some cases.
The main disadvantage of RichViewXML - it was not created by me and I can give no guaranties about it quality (I continue to support it, though). All new TRichView features are added to RVF immediately, RichViewXML updates follow with some delay.

Posted: Thu Oct 27, 2005 10:59 pm
by Guest
well ..

then how i can save the content of one rv
to an xml stream. almost someting smoot ?

Posted: Thu Oct 27, 2005 11:01 pm
by Guest
well ..

then how i can save the content of one rv
to an xml stream. almost someting smoot ?

Posted: Fri Oct 28, 2005 12:25 pm
by Sergey Tkachenko
RvXML.SaveToFile('c:\doc.xml') saves TRichView (or TRichViewEdit) assigned to RvXML.RichView.

RichViewXML has documentation as a demo project (documentation in XML files, a viewer is included)

Posted: Sat Oct 29, 2005 12:47 am
by Guest
yes i have been that.

first save the content to an xml file then load this
xml file into an richview, then i use savetostream.

but i want do it in memory.

make the convertion directly from
richview o richviewedit to and xml stream
with out save it to xml file in the HD, like you say.

Posted: Sat Oct 29, 2005 11:31 am
by Sergey Tkachenko
RvXML.SaveToStream