XML Parse

Delphi'de kod yazma ile ilgili sorularınızı bu foruma yazabilirsiniz.
Cevapla
Kullanıcı avatarı
adelphiforumz
Üye
Mesajlar: 602
Kayıt: 01 Nis 2008 05:38
Konum: İstanbul

XML Parse

Mesaj gönderen adelphiforumz »

Selamlar
Elimde Xml olarak bulunan bir dosyadaki verileri db içerisine yazmak istiyorum fakat nasıl bir döngü ile yapacağımı tam olarak çözemedim
XMLBiding denedim fakat işin içinden çıkamadım
IXMLDocument ile denedim node ve childNodes ları tam halledemedim
yadımcı olabileceklere teşekkürler
<QueryResponse xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="SmsApi">
<Response>
<ReportDetail>
<List>
<ReportDetailItem>
<Payload>DENEME</Payload>
<Xser i:nil="true"/>
<Cost>1</Cost>
<ErrorCode>0</ErrorCode>
<Id>24784074</Id>
<LastUpdated>2016-07-25T19:07:08</LastUpdated>
<MSISDN>905330</MSISDN>
<Network>1086</Network>
<Sequence>0</Sequence>
<State>Delivered</State>
<Submitted>2016-07-25T19:06:09</Submitted>
</ReportDetailItem>
<ReportDetailItem>
<Payload>DENEME</Payload>
<Xser i:nil="true"/>
<Cost>1</Cost>
<ErrorCode>0</ErrorCode>
<Id>24784075</Id>
<LastUpdated>2016-07-25T19:06:51</LastUpdated>
<MSISDN>90532</MSISDN>
<Network>1087</Network>
<Sequence>0</Sequence>
<State>Delivered</State>
<Submitted>2016-07-25T19:06:09</Submitted>
</ReportDetailItem>
<ReportDetailItem>
<Payload>DENEME</Payload>
<Xser i:nil="true"/>
<Cost>1</Cost>
<ErrorCode>0</ErrorCode>
<Id>24784076</Id>
<LastUpdated>2016-07-25T19:06:51</LastUpdated>
<MSISDN>90535</MSISDN>
<Network>1087</Network>
<Sequence>0</Sequence>
<State>Delivered</State>
<Submitted>2016-07-25T19:06:09</Submitted>
</ReportDetailItem>
</List>
</ReportDetail>
<Status>
<Code>200</Code>
<Description>OK</Description>
</Status>
</Response>
</QueryResponse>
Ehil olmayanlara sabretmek ehil olanları parlatır.
Akıllı birisinden gelen cefa, bilgisizlerin vefasından iyidir.
Bilgiye ulaştı mı ayak, kanat olur
Biz insanı kıyafetiyle ağırlar bilgisiyle uğurlarız.
Mevlana
mkysoft
Kıdemli Üye
Mesajlar: 3103
Kayıt: 26 Ağu 2003 12:35
Konum: Berlin
İletişim:

Re: XML Parse

Mesaj gönderen mkysoft »

İlgili xml'in şema dosyası olsa daha kolay olurdu. Şema olmayınca veri tipleri XmlDocument üstünde string olarak erişilebilir. Erişim sonraso bir çok kontrol yaparak veriyi dönüştürmeniz gerekecektir.
mkysoft
Kıdemli Üye
Mesajlar: 3103
Kayıt: 26 Ağu 2003 12:35
Konum: Berlin
İletişim:

Re: XML Parse

Mesaj gönderen mkysoft »

header arayınca ekomesaj sitesi çıktı. site üzerinde wsdl mevcut, web servis olarak geliştirmeniz daha kolay olur bence: http://gw.ekomesaj.com.tr/v1/soap11
Kullanıcı avatarı
adelphiforumz
Üye
Mesajlar: 602
Kayıt: 01 Nis 2008 05:38
Konum: İstanbul

Re: XML Parse

Mesaj gönderen adelphiforumz »

oraya koymuşlar fakat onlar çalışmıyormuş kendileri ile iletişime geçtim
mecbur kaldım xml üzerinden parçalamaya hatta daha önceden buna benzer bir soruyu forumda sormuştum ve
sağolsun mrmarman yardımcı olmuştu fakat bir türlü verdiği örneği xe7 içerisinde çalıştıramadım belirtilen sınıflarda
hata vermişti hala aynı sıkıntı devam ediyor.
viewtopic.php?f=2&t=34840#p187581
Ehil olmayanlara sabretmek ehil olanları parlatır.
Akıllı birisinden gelen cefa, bilgisizlerin vefasından iyidir.
Bilgiye ulaştı mı ayak, kanat olur
Biz insanı kıyafetiyle ağırlar bilgisiyle uğurlarız.
Mevlana
Kullanıcı avatarı
vkamadan
Kıdemli Üye
Mesajlar: 1935
Kayıt: 17 Mar 2004 03:52
Konum: Adapazarı
İletişim:

Re: XML Parse

Mesaj gönderen vkamadan »

Merhabalar ,
Delphi içinde standart olarak gelen "XML Data Binding" aracını kullanabilirsiniz, File-New-Other altında gelen menüde XML menüsü altından erişebilirsiniz. buraya XML inizi gösteriyorsunuz XML in yapısında bir Interface oluşturuyor rahatça erişebiliyorsunuz.
Volkan KAMADAN
www.polisoft.com.tr
Kullanıcı avatarı
adelphiforumz
Üye
Mesajlar: 602
Kayıt: 01 Nis 2008 05:38
Konum: İstanbul

Re: XML Parse

Mesaj gönderen adelphiforumz »

vkamadan hocam dediğiniz dün yaptım fakat çıkamadığım yer
satırların içerisinde nasıl dönüp veri almam lazım bunu başaramadım
teşekkürler

Kod: Tümünü seç


{****************************************************************}
{                                                                }
{                        XML Data Binding                        }
{                                                                }
{         Generated on: 25/07/2016 19:28:00                      }
{       Generated from: S:\SMS_Mobilisim_DataBinding_Query.xml   }
{   Settings stored in: S:\SMS_Mobilisim_DataBinding_Query.xdb   }
{                                                                }
{****************************************************************}

unit XmlBinding_Mobilisim_Query;

interface

uses xmldom, XMLDoc, XMLIntf;

type

{ Forward Decls }

  IXMLQueryResponseType = interface;
  IXMLResponseType = interface;
  IXMLReportDetailType = interface;
  IXMLListType = interface;
  IXMLReportDetailItemType = interface;
  IXMLStatusType = interface;

{ IXMLQueryResponseType }

  IXMLQueryResponseType = interface(IXMLNode)
    ['{EE62CA29-1174-4C4C-9B7F-DFF389BD3374}']
    { Property Accessors }
    function Get_Xmlns: Integer;
    function Get_Response: IXMLResponseType;
    procedure Set_Xmlns(Value: Integer);
    { Methods & Properties }
    property Xmlns: Integer read Get_Xmlns write Set_Xmlns;
    property Response: IXMLResponseType read Get_Response;
  end;

{ IXMLResponseType }

  IXMLResponseType = interface(IXMLNode)
    ['{B252FA65-F157-42BE-A909-DF9D320B9440}']
    { Property Accessors }
    function Get_ReportDetail: IXMLReportDetailType;
    function Get_Status: IXMLStatusType;
    { Methods & Properties }
    property ReportDetail: IXMLReportDetailType read Get_ReportDetail;
    property Status: IXMLStatusType read Get_Status;
  end;

{ IXMLReportDetailType }

  IXMLReportDetailType = interface(IXMLNode)
    ['{8EE73DA4-BC76-450A-815B-50B7C6A3F3BA}']
    { Property Accessors }
    function Get_List: IXMLListType;
    { Methods & Properties }
    property List: IXMLListType read Get_List;
  end;

{ IXMLListType }

  IXMLListType = interface(IXMLNode)
    ['{B18BDD35-581E-4EAF-8840-299B9478CFFA}']
    { Property Accessors }
    function Get_ReportDetailItem: IXMLReportDetailItemType;
    { Methods & Properties }
    property ReportDetailItem: IXMLReportDetailItemType read Get_ReportDetailItem;
  end;

{ IXMLReportDetailItemType }

  IXMLReportDetailItemType = interface(IXMLNode)
    ['{7F0DB141-12A2-4024-ACC3-311E393A4A2D}']
    { Property Accessors }
    function Get_Payload: Integer;
    function Get_Xser: Integer;
    function Get_Cost: Integer;
    function Get_ErrorCode: Integer;
    function Get_Id: Integer;
    function Get_LastUpdated: Integer;
    function Get_MSISDN: Integer;
    function Get_Network: Integer;
    function Get_Sequence: Integer;
    function Get_State: Integer;
    function Get_Submitted: Integer;
    procedure Set_Payload(Value: Integer);
    procedure Set_Xser(Value: Integer);
    procedure Set_Cost(Value: Integer);
    procedure Set_ErrorCode(Value: Integer);
    procedure Set_Id(Value: Integer);
    procedure Set_LastUpdated(Value: Integer);
    procedure Set_MSISDN(Value: Integer);
    procedure Set_Network(Value: Integer);
    procedure Set_Sequence(Value: Integer);
    procedure Set_State(Value: Integer);
    procedure Set_Submitted(Value: Integer);
    { Methods & Properties }
    property Payload: Integer read Get_Payload write Set_Payload;
    property Xser: Integer read Get_Xser write Set_Xser;
    property Cost: Integer read Get_Cost write Set_Cost;
    property ErrorCode: Integer read Get_ErrorCode write Set_ErrorCode;
    property Id: Integer read Get_Id write Set_Id;
    property LastUpdated: Integer read Get_LastUpdated write Set_LastUpdated;
    property MSISDN: Integer read Get_MSISDN write Set_MSISDN;
    property Network: Integer read Get_Network write Set_Network;
    property Sequence: Integer read Get_Sequence write Set_Sequence;
    property State: Integer read Get_State write Set_State;
    property Submitted: Integer read Get_Submitted write Set_Submitted;
  end;

{ IXMLStatusType }

  IXMLStatusType = interface(IXMLNode)
    ['{AB884716-BC54-4AF3-934A-420817E35C91}']
    { Property Accessors }
    function Get_Code: Integer;
    function Get_Description: Integer;
    procedure Set_Code(Value: Integer);
    procedure Set_Description(Value: Integer);
    { Methods & Properties }
    property Code: Integer read Get_Code write Set_Code;
    property Description: Integer read Get_Description write Set_Description;
  end;

{ Forward Decls }

  TXMLQueryResponseType = class;
  TXMLResponseType = class;
  TXMLReportDetailType = class;
  TXMLListType = class;
  TXMLReportDetailItemType = class;
  TXMLStatusType = class;

{ TXMLQueryResponseType }

  TXMLQueryResponseType = class(TXMLNode, IXMLQueryResponseType)
  protected
    { IXMLQueryResponseType }
    function Get_Xmlns: Integer;
    function Get_Response: IXMLResponseType;
    procedure Set_Xmlns(Value: Integer);
  public
    procedure AfterConstruction; override;
  end;

{ TXMLResponseType }

  TXMLResponseType = class(TXMLNode, IXMLResponseType)
  protected
    { IXMLResponseType }
    function Get_ReportDetail: IXMLReportDetailType;
    function Get_Status: IXMLStatusType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLReportDetailType }

  TXMLReportDetailType = class(TXMLNode, IXMLReportDetailType)
  protected
    { IXMLReportDetailType }
    function Get_List: IXMLListType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLListType }

  TXMLListType = class(TXMLNode, IXMLListType)
  protected
    { IXMLListType }
    function Get_ReportDetailItem: IXMLReportDetailItemType;
  public
    procedure AfterConstruction; override;
  end;

{ TXMLReportDetailItemType }

  TXMLReportDetailItemType = class(TXMLNode, IXMLReportDetailItemType)
  protected
    { IXMLReportDetailItemType }
    function Get_Payload: Integer;
    function Get_Xser: Integer;
    function Get_Cost: Integer;
    function Get_ErrorCode: Integer;
    function Get_Id: Integer;
    function Get_LastUpdated: Integer;
    function Get_MSISDN: Integer;
    function Get_Network: Integer;
    function Get_Sequence: Integer;
    function Get_State: Integer;
    function Get_Submitted: Integer;
    procedure Set_Payload(Value: Integer);
    procedure Set_Xser(Value: Integer);
    procedure Set_Cost(Value: Integer);
    procedure Set_ErrorCode(Value: Integer);
    procedure Set_Id(Value: Integer);
    procedure Set_LastUpdated(Value: Integer);
    procedure Set_MSISDN(Value: Integer);
    procedure Set_Network(Value: Integer);
    procedure Set_Sequence(Value: Integer);
    procedure Set_State(Value: Integer);
    procedure Set_Submitted(Value: Integer);
  end;

{ TXMLStatusType }

  TXMLStatusType = class(TXMLNode, IXMLStatusType)
  protected
    { IXMLStatusType }
    function Get_Code: Integer;
    function Get_Description: Integer;
    procedure Set_Code(Value: Integer);
    procedure Set_Description(Value: Integer);
  end;

{ Global Functions }

function GetQueryResponse(Doc: IXMLDocument): IXMLQueryResponseType;
function LoadQueryResponse(const FileName: string): IXMLQueryResponseType;
function NewQueryResponse: IXMLQueryResponseType;

const
  TargetNamespace = 'SmsApi';

implementation

{ Global Functions }

function GetQueryResponse(Doc: IXMLDocument): IXMLQueryResponseType;
begin
  Result := Doc.GetDocBinding('QueryResponse', TXMLQueryResponseType, TargetNamespace) as IXMLQueryResponseType;
end;

function LoadQueryResponse(const FileName: string): IXMLQueryResponseType;
begin
  Result := LoadXMLDocument(FileName).GetDocBinding('QueryResponse', TXMLQueryResponseType, TargetNamespace) as IXMLQueryResponseType;
end;

function NewQueryResponse: IXMLQueryResponseType;
begin
  Result := NewXMLDocument.GetDocBinding('QueryResponse', TXMLQueryResponseType, TargetNamespace) as IXMLQueryResponseType;
end;

{ TXMLQueryResponseType }

procedure TXMLQueryResponseType.AfterConstruction;
begin
  RegisterChildNode('Response', TXMLResponseType);
  inherited;
end;

function TXMLQueryResponseType.Get_Xmlns: Integer;
begin
  Result := AttributeNodes['xmlns'].NodeValue;
end;

procedure TXMLQueryResponseType.Set_Xmlns(Value: Integer);
begin
  SetAttribute('xmlns', Value);
end;

function TXMLQueryResponseType.Get_Response: IXMLResponseType;
begin
  Result := ChildNodes['Response'] as IXMLResponseType;
end;

{ TXMLResponseType }

procedure TXMLResponseType.AfterConstruction;
begin
  RegisterChildNode('ReportDetail', TXMLReportDetailType);
  RegisterChildNode('Status', TXMLStatusType);
  inherited;
end;

function TXMLResponseType.Get_ReportDetail: IXMLReportDetailType;
begin
  Result := ChildNodes['ReportDetail'] as IXMLReportDetailType;
end;

function TXMLResponseType.Get_Status: IXMLStatusType;
begin
  Result := ChildNodes['Status'] as IXMLStatusType;
end;

{ TXMLReportDetailType }

procedure TXMLReportDetailType.AfterConstruction;
begin
  RegisterChildNode('List', TXMLListType);
  inherited;
end;

function TXMLReportDetailType.Get_List: IXMLListType;
begin
  Result := ChildNodes['List'] as IXMLListType;
end;

{ TXMLListType }

procedure TXMLListType.AfterConstruction;
begin
  RegisterChildNode('ReportDetailItem', TXMLReportDetailItemType);
  inherited;
end;

function TXMLListType.Get_ReportDetailItem: IXMLReportDetailItemType;
begin
  Result := ChildNodes['ReportDetailItem'] as IXMLReportDetailItemType;
end;

{ TXMLReportDetailItemType }

function TXMLReportDetailItemType.Get_Payload: Integer;
begin
  Result := ChildNodes['Payload'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Payload(Value: Integer);
begin
  ChildNodes['Payload'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Xser: Integer;
begin
  Result := ChildNodes['Xser'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Xser(Value: Integer);
begin
  ChildNodes['Xser'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Cost: Integer;
begin
  Result := ChildNodes['Cost'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Cost(Value: Integer);
begin
  ChildNodes['Cost'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_ErrorCode: Integer;
begin
  Result := ChildNodes['ErrorCode'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_ErrorCode(Value: Integer);
begin
  ChildNodes['ErrorCode'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Id: Integer;
begin
  Result := ChildNodes['Id'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Id(Value: Integer);
begin
  ChildNodes['Id'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_LastUpdated: Integer;
begin
  Result := ChildNodes['LastUpdated'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_LastUpdated(Value: Integer);
begin
  ChildNodes['LastUpdated'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_MSISDN: Integer;
begin
  Result := ChildNodes['MSISDN'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_MSISDN(Value: Integer);
begin
  ChildNodes['MSISDN'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Network: Integer;
begin
  Result := ChildNodes['Network'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Network(Value: Integer);
begin
  ChildNodes['Network'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Sequence: Integer;
begin
  Result := ChildNodes['Sequence'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Sequence(Value: Integer);
begin
  ChildNodes['Sequence'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_State: Integer;
begin
  Result := ChildNodes['State'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_State(Value: Integer);
begin
  ChildNodes['State'].NodeValue := Value;
end;

function TXMLReportDetailItemType.Get_Submitted: Integer;
begin
  Result := ChildNodes['Submitted'].NodeValue;
end;

procedure TXMLReportDetailItemType.Set_Submitted(Value: Integer);
begin
  ChildNodes['Submitted'].NodeValue := Value;
end;

{ TXMLStatusType }

function TXMLStatusType.Get_Code: Integer;
begin
  Result := ChildNodes['Code'].NodeValue;
end;

procedure TXMLStatusType.Set_Code(Value: Integer);
begin
  ChildNodes['Code'].NodeValue := Value;
end;

function TXMLStatusType.Get_Description: Integer;
begin
  Result := ChildNodes['Description'].NodeValue;
end;

procedure TXMLStatusType.Set_Description(Value: Integer);
begin
  ChildNodes['Description'].NodeValue := Value;
end;

end.
Ehil olmayanlara sabretmek ehil olanları parlatır.
Akıllı birisinden gelen cefa, bilgisizlerin vefasından iyidir.
Bilgiye ulaştı mı ayak, kanat olur
Biz insanı kıyafetiyle ağırlar bilgisiyle uğurlarız.
Mevlana
Kullanıcı avatarı
vkamadan
Kıdemli Üye
Mesajlar: 1935
Kayıt: 17 Mar 2004 03:52
Konum: Adapazarı
İletişim:

Re: XML Parse

Mesaj gönderen vkamadan »

Merhaba Interface hatalı oluşmuş , "ListType" isimli sınıf nodeCollection olmalıydı, ben sizin XML için basit bir örnek hazırladım, Interface mob.pas içinde, incelerseniz kolayca anlayacaksınız.
Dosya ekleri
test_mob.zip
(18.09 KiB) 137 kere indirildi
Volkan KAMADAN
www.polisoft.com.tr
Kullanıcı avatarı
adelphiforumz
Üye
Mesajlar: 602
Kayıt: 01 Nis 2008 05:38
Konum: İstanbul

Re: XML Parse

Mesaj gönderen adelphiforumz »

Selam Volkan Hocam
Çok teşekkür ederim allah razı olsun.
Bu konuda öğrenmek için bişey sormak istiyorum
Ben File->New->Other->XML Data Binding seçip disk üzerindeki Xml dosyasını gösterdim
fakat senin oluşturduğun binding dosyası ile benimkinin içeriği farklı
Ayrıca çalışma sırasında elimdeki String olarak bulunan xml dosyasını disk üzerine kaydedip load etmeden
tanımlamış olduğun intXML : IXMLQueryResponseType nesnesine direkt atabilirmiyim.
Teşekkürler
Ehil olmayanlara sabretmek ehil olanları parlatır.
Akıllı birisinden gelen cefa, bilgisizlerin vefasından iyidir.
Bilgiye ulaştı mı ayak, kanat olur
Biz insanı kıyafetiyle ağırlar bilgisiyle uğurlarız.
Mevlana
Kullanıcı avatarı
vkamadan
Kıdemli Üye
Mesajlar: 1935
Kayıt: 17 Mar 2004 03:52
Konum: Adapazarı
İletişim:

Re: XML Parse

Mesaj gönderen vkamadan »

Merhaba ,
Rica ederim.
Kullanılan Delphi sürümününe göre farklılıklar oluşabilir.
Evet ilgili unit in içinde (mob.pas) LoadQueryResponse yerine GetQueryResponse u kullanabilirsiniz, bu metoda IXMLDocument tipinde parametre geçmelisini,z formunuza TXMLDocument ekleyip çalışma anında TXMLDocument.XML.text özelliğine string olarak XML değeri atamasını yapıp interface i intXML := GetQueryResponse( XMLDocument1 ) şeklinde yükleyebilirsiniz.
Volkan KAMADAN
www.polisoft.com.tr
Cevapla