Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSD to Delphi Classes without XML binding

Perhaps this has been asked before, but I haven't found it with regards to Delphi - I have used a XSD.exe in Visual Studio that does exactly this: converts XSD into 'plain vanilla' classes representing the entities specified in the XSD - not bound to XML document - classes for creating the structures in the XSD, not accessing data that conforms to the structure outlined in the XSD.

I am looking for a utility or product that will do this (that doesn't cost big bucks...) : Example, I have a schema like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="TDelphiClass">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="ID"/>
                <xs:element ref="ConnectionString"/>
                <xs:element ref="Group"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="ID" type="xs:integer"/>
    <xs:element name="ConnectionString" type="xs:string"/>
    <xs:element name="Group"type="xs:double"/>
</xs:schema>

I want to generate a Delphi unit/class that looks like this:

unit uDelphiClass;

interface

uses
  Classes, SysUtils;

type
  TDelphiClass = class(TObject)
    fID: Integer;
    fConnectionString: string;
    fGroup: Double;
  end;

implementation

end.
like image 837
Vector Avatar asked May 02 '11 05:05

Vector


2 Answers

Reading between the lines (please use less abbreviations, for instance, VS has multiple meanings, even in computing), and You probably used the XSD.EXE tool in Visual Studio or the .NET SDK to generate your source code in the C# or VB.NET language.

If you have Delphi Prism, you can use XSD.EXE to generate Delphi Prism source code.

The Delphi Prism language is very close to the Delphi native language, so that will give you a kick start.

This should work with the Delphi Prism trial too.

BTW: Why do you not want to use the Delphi native code generated by the XML Data Binding Wizard in a standalone way? It is interface based, but is pretty fast and works very well.

like image 105
Jeroen Wiert Pluimers Avatar answered Oct 29 '22 06:10

Jeroen Wiert Pluimers


http://sourceforge.net/projects/xxsd2code/ generates C++, C#, C++/CLI and Java - and it looks like the included 'LanguageWriter' classes are not too complicated to extend them for Delphi. The Java LanguageWriter for example has less than 400 lines. If there is interest in the Delphi community this could be implemented and contributed in a short timeframe...

like image 4
mjn Avatar answered Oct 29 '22 06:10

mjn