XML ile çalışma

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
nosedive
Üye
Mesajlar: 238
Kayıt: 16 May 2004 07:48

XML ile çalışma

Mesaj gönderen nosedive »

Kod: Tümünü seç



{*******************************************************************************}
{                                                                               }
{                               XML Data Binding                                }
{                                                                               }
{         Generated on: 13.10.2006 15:51:40                                     }
{       Generated from: C:\Documents and Settings\Yonetici\Desktop\online.xml   }
{   Settings stored in: C:\Documents and Settings\Yonetici\Desktop\online.xdb   }
{                                                                               }
{*******************************************************************************}

unit online;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLRssType = interface;
  IXMLChannelType = interface;
  IXMLItemType = interface;

{ IXMLRssType }

  IXMLRssType = interface(IXMLNode)
    ['{36F8C5BF-2192-4735-ADD0-C4F984D16F1E}']
    { Property Accessors }
    function Get_Version: WideString;
    function Get_Channel: IXMLChannelType;
    procedure Set_Version(Value: WideString);
    { Methods & Properties }
    property Version: WideString read Get_Version write Set_Version;
    property Channel: IXMLChannelType read Get_Channel;
  end;

{ IXMLChannelType }

  IXMLChannelType = interface(IXMLNodeCollection)
    ['{34EE0BAD-E579-4074-98C6-2B7785B08C2A}']
    { Property Accessors }
    function Get_Item(Index: Integer): IXMLItemType;
    { Methods & Properties }
    function Add: IXMLItemType;
    function Insert(const Index: Integer): IXMLItemType;
    property Item[Index: Integer]: IXMLItemType read Get_Item; default;
  end;

{ IXMLItemType }

  IXMLItemType = interface(IXMLNode)
    ['{B299BA99-B246-4D1F-A90A-FDA3FB0D3B93}']
    { Property Accessors }
    function Get_Kategori: WideString;
    function Get_Baslik: WideString;
    function Get_Giris: WideString;
    function Get_Linki: WideString;
    function Get_Resim: WideString;
    procedure Set_Kategori(Value: WideString);
    procedure Set_Baslik(Value: WideString);
    procedure Set_Giris(Value: WideString);
    procedure Set_Linki(Value: WideString);
    procedure Set_Resim(Value: WideString);
    { Methods & Properties }
    property Kategori: WideString read Get_Kategori write Set_Kategori;
    property Baslik: WideString read Get_Baslik write Set_Baslik;
    property Giris: WideString read Get_Giris write Set_Giris;
    property Linki: WideString read Get_Linki write Set_Linki;
    property Resim: WideString read Get_Resim write Set_Resim;
  end;

{ Forward Decls }

  TXMLRssType = class;
  TXMLChannelType = class;
  TXMLItemType = class;

{ TXMLRssType }

  TXMLRssType = class(TXMLNode, IXMLRssType)
  protected
    { IXMLRssType }
    function Get_Version: WideString;
    function Get_Channel: IXMLChannelType;
    procedure Set_Version(Value: WideString);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLChannelType }

  TXMLChannelType = class(TXMLNodeCollection, IXMLChannelType)
  protected
    { IXMLChannelType }
    function Get_Item(Index: Integer): IXMLItemType;
    function Add: IXMLItemType;
    function Insert(const Index: Integer): IXMLItemType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLItemType }

  TXMLItemType = class(TXMLNode, IXMLItemType)
  protected
    { IXMLItemType }
    function Get_Kategori: WideString;
    function Get_Baslik: WideString;
    function Get_Giris: WideString;
    function Get_Linki: WideString;
    function Get_Resim: WideString;
    procedure Set_Kategori(Value: WideString);
    procedure Set_Baslik(Value: WideString);
    procedure Set_Giris(Value: WideString);
    procedure Set_Linki(Value: WideString);
    procedure Set_Resim(Value: WideString);
  end;

{ Global Functions }

function Getrss(Doc: IXMLDocument): IXMLRssType;
function Loadrss(const FileName: WideString): IXMLRssType;
function Newrss: IXMLRssType;

const
  TargetNamespace = '';

implementation

{ Global Functions }

function Getrss(Doc: IXMLDocument): IXMLRssType;
begin
  Result := Doc.GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType;
end;

function Loadrss(const FileName: WideString): IXMLRssType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType;
end;

function Newrss: IXMLRssType;
begin
  Result := NewXMLDocument.GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType;
end;

{ TXMLRssType }

procedure TXMLRssType.AfterConstruction;
begin
  RegisterChildNode('channel', TXMLChannelType);
  inherited;
end;

function TXMLRssType.Get_Version: WideString;
begin
  Result := AttributeNodes['version'].Text;
end;

procedure TXMLRssType.Set_Version(Value: WideString);
begin
  SetAttribute('version', Value);
end;

function TXMLRssType.Get_Channel: IXMLChannelType;
begin
  Result := ChildNodes['channel'] as IXMLChannelType;
end;

{ TXMLChannelType }

procedure TXMLChannelType.AfterConstruction;
begin
  RegisterChildNode('item', TXMLItemType);
  ItemTag := 'item';
  ItemInterface := IXMLItemType;
  inherited;
end;

function TXMLChannelType.Get_Item(Index: Integer): IXMLItemType;
begin
  Result := List[Index] as IXMLItemType;
end;

function TXMLChannelType.Add: IXMLItemType;
begin
  Result := AddItem(-1) as IXMLItemType;
end;

function TXMLChannelType.Insert(const Index: Integer): IXMLItemType;
begin
  Result := AddItem(Index) as IXMLItemType;
end;

{ TXMLItemType }

function TXMLItemType.Get_Kategori: WideString;
begin
  Result := ChildNodes['kategori'].Text;
end;

procedure TXMLItemType.Set_Kategori(Value: WideString);
begin
  ChildNodes['kategori'].NodeValue := Value;
end;

function TXMLItemType.Get_Baslik: WideString;
begin
  Result := ChildNodes['baslik'].Text;
end;

procedure TXMLItemType.Set_Baslik(Value: WideString);
begin
  ChildNodes['baslik'].NodeValue := Value;
end;

function TXMLItemType.Get_Giris: WideString;
begin
  Result := ChildNodes['giris'].Text;
end;

procedure TXMLItemType.Set_Giris(Value: WideString);
begin
  ChildNodes['giris'].NodeValue := Value;
end;

function TXMLItemType.Get_Linki: WideString;
begin
  Result := ChildNodes['linki'].Text;
end;

procedure TXMLItemType.Set_Linki(Value: WideString);
begin
  ChildNodes['linki'].NodeValue := Value;
end;

function TXMLItemType.Get_Resim: WideString;
begin
  Result := ChildNodes['resim'].Text;
end;

procedure TXMLItemType.Set_Resim(Value: WideString);
begin
  ChildNodes['resim'].NodeValue := Value;
end;

end.

yukardaki XML dosyası ile çalışıyorum. Makalede yazılan şekilde işlemi yaptım ancak ;

Kod: Tümünü seç

procedure TForm1.Button1Click(Sender: TObject);
var
 XMLBir : IXMLRssType;
 XMLIki : IXMLChannelType;
begin
XMLBir := Loadrss('online.xml');
XMLIki :=
Listbox1.Items.Add('bir '+ XMLBir.version);

end;
yukarda XMLBir.version şeklinde kodda hata alıyorum

Kod: Tümünü seç

EDOMParserError with message 'sistem hatası.....' 
evet XMLrssType in içeriği yok onlar başlıklar..ondan olabilir..ancak

IXMLChannelType
IXMLItemType

ların Loadrss gibi bi metodu yok ?

bu XML üzerinde nasıl işlem yapabilirim..XML in yapısında bi problem görünüyormu.

Yardımcı olacak arkadaşlar şimdiden teşekkürler...
Kullanıcı avatarı
mrmarman
Üye
Mesajlar: 4741
Kayıt: 09 Ara 2003 08:13
Konum: İstanbul
İletişim:

Mesaj gönderen mrmarman »

- Bilgi :

- Neden MSN'den soru sorulduğunda hemen kabul etmediğimiz böylece daha da açık bir şekilde ıspat edilmiş oldu. Gerekli bilgi alışverişinden sonra sorun çözülünce forumla irtibat kurulmamış. Şimdi cevaplanmamış mesajlara bakarken farkettim.

- Benzer sorunu yaşayanlar için referans olsun diye bir iki şey yazayım istedim.

- Bu konu @nosedive ile MSN aracılığıyla görüşüldü. Sonuç olarak kodda hata olmadığı, aşağıdaki örnek ile bilgilerin aşağıdaki şekilde çekilebileceği sonucunda mutabık olundu.

Kod: Tümünü seç

var
  XMLBir : IXMLRssType;
  XMLIki : IXMLChannelType;
  Sayac   : Integer;
begin
  XMLBir := Loadrss('online.xml');
  XMLiki := XMLBir.Channel;
  Listbox1.Items.Add('bir '+ XMLBir.version);
  For Sayac := 0 to XMLiki.Count-1 do begin
    ListBox1.Items.Add( Format('%d/%d - %s', [Sayac+1, XMLiki.Count, XMLiki[Sayac].Baslik]) )
  end;
end;
DipNot : LoadRSS fonksiyonu, XML databinding ile oluşan unit içindeki fonksiyondur.

Kod: Tümünü seç

function Loadrss(const FileName: WideString): IXMLRssType; 
begin 
  Result := LoadXMLDocument(FileName).GetDocBinding('rss', TXMLRssType, TargetNamespace) as IXMLRssType; 
end; 
Resim
Resim ....Resim
Kullanıcı avatarı
nosedive
Üye
Mesajlar: 238
Kayıt: 16 May 2004 07:48

pardon

Mesaj gönderen nosedive »

daha once bir iki kez sorunun çözümünü yazmıştım başka konularda...ama bu sefer gözden kaçmış pardon...

daha dikkatli olmak lazım...
Cevapla