Recent

Author Topic: XML Data Binding  (Read 8194 times)

jom

  • Newbie
  • Posts: 2
XML Data Binding
« on: January 07, 2012, 11:12:04 pm »
Pesquisei e não encontrei nenhum framework para se trabalhar XML com binding no Lazarus, nem mesmo algum projeto em desenvolvimento deste tipo. Se alguém souber, por gentileza me avise.
Como não achei nada a respeito, então resolvi brincar um pouco com o tema e consegui fazer algo que imaginei que poderia ser, utilizando a RTL pra isso. A idéia é transformar classes em XML e XML em classes.
A principio qualquer classe pode ser transformada em xml, mas imagino que o ideal seria ter uma forma de controlar como os elementos deveriam se comportar. Em java alguns frameworks usam annotations para especificar os elementos e atributos, mas como Lazarus não tem suporte a atributos, acho que deveria então se criar uma interface para isso, então fiz uma interface para definir descritores para os campos, mas neste caso as classes devem herdar de TPersistent. É claro que a interface deveria seguir alguma especificação, mas não me preocupei com isso agora pois é apenas um tiro no escuro.

Mas tudo é apenas testes, apenas estou procurando o caminho de como isso deveria ser feito, por isso fiz somente a parte de transformar objetos em xml. Segue em anexo o pacote com a classe TLazXMLDataBinding que criei e o projeto de teste.

---

I researched and not found a framework for working with XML binding in Lazarus, or even developing a project of this type. If anyone knows, please let me know.
As I did not find anything about it, so I decided to play around with the theme and managed to do something that could be imagined, using the RTL for this. The idea is to transform objects to XML and XML to objects.
In principle, any class can be transformed into xml, but I guess the ideal would be to have a way to control how the elements should behave. In some frameworks using Java annotations to specify the elements and attributes, but as Lazarus does not support attributes, I think it should then create an interface for this, so I made an interface to define descriptors for the fields, but in this case the classes are inherit from TPersistent. Of course, that the interface should follow any specifications, but did not bother with it now because it's only a shot in the dark.

But it's just testing, I'm just looking for the way how it should be done, why did only part of transforming objects into XML. Attached is the package with the class TLazXMLDataBinding and I created the test project.

Sorry my bad English, I'm learning yet.
« Last Edit: January 07, 2012, 11:53:43 pm by jom »

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: XML Data Binding
« Reply #1 on: January 08, 2012, 11:44:41 am »
How does XML data binding differs from component streaming?

jom

  • Newbie
  • Posts: 2
Re: XML Data Binding
« Reply #2 on: January 08, 2012, 02:37:03 pm »
How does XML data binding differs from component streaming?
My test was based on this. But component streaming is only for components, is not it?
We need more flexibility, define attributes and elements, formatting, etc. for use with others applications.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8835
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: XML Data Binding
« Reply #3 on: January 08, 2012, 09:37:15 pm »
Quote
But component streaming is only for components, is not it?
Depending on your definition of component. Everything extends from TPersistent/TComponent could be streamed, with TComponent descendant having the ability to stream its children as well.

danialshdy8

  • Newbie
  • Posts: 2
Re: XML Data Binding
« Reply #4 on: June 07, 2012, 12:15:17 pm »
you can also use worker classes, which reads/writes a TComponent to/from a stream.

danialshdy8

  • Newbie
  • Posts: 2
Re: XML Data Binding
« Reply #5 on: June 07, 2012, 12:19:18 pm »
also, why do you need an interface, you coul use a standalone xml data binding tool and it will work just as well in reading your xml, plus you can output whatever you like, c++ or c#, even java.

 

TinyPortal © 2005-2018