XSD to Delphi Classes without XML binding

五迷三道 提交于 2019-12-21 07:22:09

问题


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.

回答1:


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.




回答2:


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...



来源:https://stackoverflow.com/questions/5853820/xsd-to-delphi-classes-without-xml-binding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!