views:

441

answers:

1

I have this XML for a table structure in Oracle (export option in PL/SQL developer). How can I generate code in C# for get entity class?

<?xml version="1.0" encoding="utf-8"?>
<ROWDATA>
  <ROW>
    <Name>ID_TRANSACCION</Name>
    <Type>NUMBER(12)</Type>
    <Nullable></Nullable>
    <Default></Default>
    <Comments>Identificador unico de la transacci&#243;n.</Comments>
  </ROW>
  <ROW>
    <Name>ID_RECIBO</Name>
    <Type>NUMBER(12)</Type>
    <Nullable></Nullable>
    <Default></Default>
    <Comments>Identificador unico del recibo.</Comments>
  </ROW>
  <ROW>
    <Name>IMPORTE_COBRAR</Name>
    <Type>NUMBER(10,2)</Type>
    <Nullable>Y</Nullable>
    <Default></Default>
    <Comments>Importe a cobrar</Comments>
  </ROW>
</ROWDATA>

Thanks!

A: 

Look into xsd.exe - this tool allows you to create an xsd schema from a sample xml document (your export form Oracle) and create a .net class from a given xsd schema.

Now that your sample code is visible it's clear that you would need to transform the xml before you could use it in connection with xsd.exe.

If you are looking for oracle support of the .NET EntityFramework you need to use a specific Oracle provider. One example would be DataDirect.


sample xslt for schema generation

<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;
    <xsl:output method="xml" omit-xml-declaration="no" indent="yes"/>

    <xsl:template match="/">
        <xsl:element name="xsd:schema">
            <xsl:attribute name="attributeFormDefault">
                qualified
            </xsl:attribute>
            <xsl:attribute name="elementFormDefault">
                qualified
            </xsl:attribute>
            <xsl:apply-templates />
        </xsl:element>
    </xsl:template>

    <xsl:template match="ROWDATA">
        <xsl:element name="xsd:element">
            <xsl:attribute name="name">
                <xsl:value-of select="local-name()"/>
            </xsl:attribute>
            <xsl:element name="xsd:complexType">
                <xsl:element name="xsd:sequence">
                    <xsl:apply-templates />
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>

    <xsl:template match="ROW">
        <xsl:element name="xsd:element">
            <xsl:attribute name="name">
                <xsl:value-of select="./Name"/>
            </xsl:attribute>
            <xsl:attribute name="nillable">
                <xsl:value-of select="contains(./Nullable, 'Y')"/>
            </xsl:attribute>
            <xsl:if test="./Default != ''">
                <xsl:attribute name="default">
                    <xsl:value-of select="./Default"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:element name="xsd:annotation">
                <xsl:element name="xsd:documentation">
                    <xsl:value-of select="./Comments"/>
                </xsl:element>
            </xsl:element>
            <xsl:element name="xsd:simpleType">
                <xsl:element name="xsd:restriction">
                    <xsl:attribute name="base">xsd:decimal</xsl:attribute>
                    <!-- elaborate data type here -->
                </xsl:element>
            </xsl:element>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

The resulting schema document can be used as an input for xsd.exe.

Filburt