5

Using Delphi XE:

XML data binding wizard generates Delphi class based on XML/XSD - works great.

BUT I also need to go the other way: Convert Delphi classes into XML. I don't find any support for that in XE. (I know this is quite simple to accomplish with C#, .NET, but obviously, since Delphi doesn't really support Reflection it's a lot more difficult than with C#)

One option I do have it is write the class in C# with SharpDevelop and use the MS utility (which I believe is a free download) to generate XML from the C# code. I also have VS 2005 that supports this, but it's not installed and I'd prefer not get to involved with it).

Anyone have a suggestion as to how to go about getting this done: Straight from Delphi to XML/XSD? An open source tool would be nice, or some good units that will do this.

Vector
  • 10,879
  • 12
  • 61
  • 101

2 Answers2

5

The NativeXml and OmniXML open source libraries can convert Delphi objects to XML (not XSD). They support object serialization and deserialization even with Delphi versions before 2010.

So it would be possible to use them in a first step to create a XML file, which then can be passed to the Data Binding Wizard for Delphi class code generation.

mjn
  • 36,362
  • 28
  • 176
  • 378
  • Thanks - will check out. I don't need to go back to Delphi. Just need to represent Delphi class as XML. – Vector Mar 28 '13 at 19:58
4

Robert Love wrote an article in late 2009 covering that topic: Xml Serialization - Basic Usage. It uses the "new" RTTI available as of Delphi 2010.

Rob Kennedy
  • 161,384
  • 21
  • 275
  • 467
  • 2
    Thanks - definitely a good start. Not familiar with the 'new' RTTI stuff since I have a bad taste in my mouth from the 'old' RTTI stuff. :-) But this looks easy. Question is how much more legwork will I have to do to represent a more complex class - his example is very simplistic. – Vector Mar 28 '13 at 17:56
  • 1
    @Mikey if you want to be able to cover 'all', you have to do a lot of work, but if you keep it simple, it is OK. That's why the Delphi XML data binding wizard supports so little XML features. Take into account that you cannot represent all classes as XML and vice versa. – Jeroen Wiert Pluimers Mar 28 '13 at 19:23
  • Thanks - no certainly I cannot represent everything in XML. What I need to do is more than represented in that simplistic example - need to work with nested lists/arrays, etc. We shall see... if worse come to worse I can do it by hand as well. – Vector Mar 28 '13 at 20:00