Page 1 of 1

Open RSS channel

Posted: Tue Feb 24, 2015 9:20 pm
by volod3000
Hi,

Try to view the rss-channel in RichView, through RichViewXML, but always a mistake
(No root element.) and in RichView empty

That's part of the code:

Code: Select all

var rssUrl: String = 'http://112.ua/rss';

procedure TForm1.Button2Click(Sender: TObject);
var
   RssXml: String;
   Stream: TFileStream;
   f: TextFile;

begin
    RichViewEdit1.Clear;
    AssignFile (f, 'myxml.txt');
    Rewrite (f);

      IdHTTP1.HandleRedirects := true;
      IdHTTP1.ReadTimeout := 5000;
      IdHTTP1.Request.ContentEncoding := 'UTF-8';
    cli:= 2;
  try
      RssXml := IdHTTP1.Get(rssUrl);
  except
    on E: Exception do
    begin
      ShowMessage ('Error: ' + E.Message);
      Exit;
    end;
  end;

     WriteLn (f, RssXml);
     CloseFile (f);
  try
    try
     Stream := TFileStream.Create('myxml.txt', fmOpenRead);//properties.xml
     Stream.Position:= 0;
    except
     ShowMessage('Файл не может быть загружен.');
     Exit;
    end;


     RichViewXML1.RootElement:= 'channel';

     RichViewXML1.LoadFromStream(Stream);
     RichViewEdit1.Format;

  finally
     Stream.Free;
  end;

end;

procedure TForm1.RichViewEdit1Jump(Sender: TObject; id: Integer);
var 
      ItemNo: Integer;
      RVData: TCustomRVFormattedData;
      s: String;
      Tag: string;

begin

  RichViewEdit1.GetJumpPointLocation(id, RVData, ItemNo);
  Tag := RVData.GetItemTag(ItemNo);
  RichViewXML1.LoadFromFile(RichViewXML1.BaseFilePath +Tag + '.xml');
  RichViewEdit1.Format;
end;

That's part of the code xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>Новости 112.ua</title>
        <link>http://portal.112.ua/</link>
        <description>112.UA RSS feed</description>
        <language>ru-ru</language>
        <pubDate>Tue, 24 Feb 2015 14:02:10 +0200</pubDate>
        <ttl>300</ttl>
        <image>
            <url>http://112.ua/static/img/logo_112_ru.jpg</url>
            <title>Новости 112.ua - </title>
            <link>http://portal.112.ua/</link>
        </image>
        
        <item>
            <title><![CDATA[Гуманитарное сообщество заявляет о намерении привлечь 316 млн долл. для помощи 3,2 млн украинцев]]></title>
            <link>http://112.ua/ekonomika/gumanitarnoe-soobschestvo-zayavlyaet-o-namerenii-privlech-316-mln-doll-dlya-pomoschi-3-2-mln-ukraincev-194993.html</link>
            <description><![CDATA[ <img src="http://image.112.ua/300x225/Jan2015/117935.jpg" alt="новости 112"/>
            По словам Уокера, более 2 миллиона человек проживает в районах, временно неподконтрольных Украине и также нуждается в поддержке, поскольку доступ к услугам у них ограничен]]></description>
            <fulltext><![CDATA[]]></fulltext>
            <pubDate>Tue, 24 Feb 2015 13:59:33 +0200</pubDate>
            <category>Экономика</category>
            <guid>http://112.ua/ekonomika/gumanitarnoe-soobschestvo-zayavlyaet-o-namerenii-privlech-316-mln-doll-dlya-pomoschi-3-2-mln-ukraincev-194993.html</guid>
            <enclosure length="8" url="http://image.112.ua/300x225/Jan2015/117935.jpg" type="image/jpeg"/>
        </item>
</channel>
</rss> 



Do not scold much, I'm just learning.
Where the error, please tell me.

Posted: Tue Feb 24, 2015 9:39 pm
by Sergey Tkachenko
RichViewXML is not designed to view arbitrary XML documents.
It allows saving TRichView document in XML and loading it.

Posted: Wed Feb 25, 2015 11:47 am
by volod3000
Sergey Tkachenko wrote:RichViewXML is not designed to view arbitrary XML documents.
It allows saving TRichView document in XML and loading it.
Understood you, thank you