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

Demos, code samples. Only questions related to the existing topics are allowed here.
Post Reply
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

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

Post 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;
Guest

Post by Guest »

Prety :D
an aprendiz

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

Post 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
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RichViewXML can be found here: http://www.trichview.com/resources/xml
guest

Use XML

Post 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
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
Guest

Post by Guest »

well ..

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

Post by Guest »

well ..

then how i can save the content of one rv
to an xml stream. almost someting smoot ?
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
Guest

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17253
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

RvXML.SaveToStream
Post Reply