XML到XSD的转换

XML到XSD的转换,xml,xsd,Xml,Xsd,我在XSD文件中翻译了一个XML。当我试图在SUP中导入/使用XSD文件时,我收到一个“执行错误”: XML和XSD都是自动创建的(由SAP、XML和XSD创建),所以我需要一些指导:D 以下是XML: <?xml version="1.0" encoding="utf-8"?> <edmx:Edmx Version="1.0" xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" xmlns:gp="

我在XSD文件中翻译了一个XML。当我试图在SUP中导入/使用XSD文件时,我收到一个“执行错误”:

XML和XSD都是自动创建的(由SAP、XML和XSD创建),所以我需要一些指导:D

以下是XML:

<?xml version="1.0" encoding="utf-8"?>
<edmx:Edmx Version="1.0" 
  xmlns:edmx="http://schemas.microsoft.com/ado/2007/06/edmx" 
  xmlns:gp="http://www.sap.com/Protocols/SAPData/GenericPlayer" 
  xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" 
  xmlns:sap="http://www.sap.com/Protocols/SAPData">
    <edmx:DataServices m:DataServiceVersion="2.0">
        <Schema Namespace="Z_SERVICE_BANK_V3" 
                xmlns="http://schemas.microsoft.com/ado/2008/09/edm">
            <EntityType Name="Bank" sap:content-version="1">
                <Key>
                    <PropertyRef Name="bankCountry"/>
                    <PropertyRef Name="bankID"/>
                </Key>
                <Property Name="bankCountry" Type="Edm.String" Nullable="false" MaxLength="3" sap:label="Bank Country" sap:filterable="false"/>
                <Property Name="bankID" Type="Edm.String" Nullable="false" MaxLength="15" sap:label="Bank Key" sap:filterable="false"/>
                <Property Name="bankName" Type="Edm.String" MaxLength="60" sap:label="Bank name" sap:filterable="false"/>
                <Property Name="region" Type="Edm.String" MaxLength="3" sap:label="Region" sap:filterable="false"/>
                <Property Name="street" Type="Edm.String" MaxLength="35" sap:label="Street" sap:filterable="false"/>
                <Property Name="city" Type="Edm.String" MaxLength="35" sap:label="City" sap:filterable="false"/>
            </EntityType>
            <EntityContainer Name="Z_SERVICE_BANK_V3" m:IsDefaultEntityContainer="true">
                <EntitySet Name="BankCollection" EntityType="Z_SERVICE_BANK_V3.Bank" sap:content-version="1"/>
            </EntityContainer>
        </Schema>
    </edmx:DataServices>
</edmx:Edmx>

这是XSD:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/ado/2008/09/edm">
    <xs:element name="Schema">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="EntityType">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Key">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="PropertyRef" maxOccurs="unbounded" minOccurs="0">
                                            <xs:complexType>
                                                <xs:simpleContent>
                                                    <xs:extension base="xs:string">
                                                        <xs:attribute type="xs:string" name="Name" use="optional"/>
                                                    </xs:extension>
                                                </xs:simpleContent>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Property" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Name" use="optional"/>
                                            <xs:attribute type="xs:string" name="Type" use="optional"/>
                                            <xs:attribute type="xs:string" name="Nullable" use="optional"/>
                                            <xs:attribute type="xs:byte" name="MaxLength" use="optional"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:label"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:filterable"/>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute type="xs:string" name="Name"/>
                        <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:content-version"/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="EntityContainer">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="EntitySet">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Name"/>
                                            <xs:attribute type="xs:string" name="EntityType"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:content-version"/>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute type="xs:string" name="Name"/>
                        <xs:attribute xmlns:met="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" ref="met:IsDefaultEntityContainer"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute type="xs:string" name="Namespace"/>
        </xs:complexType>
    </xs:element>
</xs:schema>


有什么想法吗?

您给出的XML示例在几个名称空间中包含元素和属性:

XSD模式文档为单个目标命名空间声明组件(元素、属性、类型);至少需要四个模式文档来声明XML文档中的所有元素和属性

您生成的XSD包含文档的一部分,而不是全部(它从{}Schema元素开始,而不是从{}Edmx元素开始),并且它没有用于其他名称空间的xsl:import。简短回答:要么您没有正确调用模式生成器,要么它不适合您正在设置的任务。您可能需要(1)更强大的黑盒解决方案或(2)更好地理解XSD及其使用,或两者兼而有之


但在短期内——所有涉及的名称空间都是由大型有能力的技术组织定义的。为什么要为这些名称空间编写自己的模式?您是否从名称空间的所有者那里查找过定义这些格式的XSD模式文档?

我使用同一个站点“验证”了这两个文件。我收到了相同的错误,但我不理解:D Src resolve.4.2:错误解析组件“sap:label”。检测到“sap:label”位于命名空间“”中,但此命名空间中的组件不可从架构文档“null”引用。如果名称空间不正确,可能需要更改“sap:label”的前缀。如果这是正确的名称空间,那么应该在“null”中添加一个适当的“import”标记。嗨,XML和XSD不是手动生成的,它们是由SAP生成的。我只是想了解这个问题,向SAP专家提出一个更好的问题,以解决这个问题:)。是的,您明确表示XSD不是手动生成的。如果您想解决这个问题,您可以找到更好的方法来生成模式,或者了解模式是如何工作的(或者找到由相关名称空间的所有者创建的模式)。如果你想向别人解释这个问题,你别无选择;您必须从理解问题开始,这意味着您必须从学习XSD模式文档和名称空间如何交互开始。
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" attributeFormDefault="unqualified" elementFormDefault="qualified" targetNamespace="http://schemas.microsoft.com/ado/2008/09/edm">
    <xs:element name="Schema">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="EntityType">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="Key">
                                <xs:complexType>
                                    <xs:sequence>
                                        <xs:element name="PropertyRef" maxOccurs="unbounded" minOccurs="0">
                                            <xs:complexType>
                                                <xs:simpleContent>
                                                    <xs:extension base="xs:string">
                                                        <xs:attribute type="xs:string" name="Name" use="optional"/>
                                                    </xs:extension>
                                                </xs:simpleContent>
                                            </xs:complexType>
                                        </xs:element>
                                    </xs:sequence>
                                </xs:complexType>
                            </xs:element>
                            <xs:element name="Property" maxOccurs="unbounded" minOccurs="0">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Name" use="optional"/>
                                            <xs:attribute type="xs:string" name="Type" use="optional"/>
                                            <xs:attribute type="xs:string" name="Nullable" use="optional"/>
                                            <xs:attribute type="xs:byte" name="MaxLength" use="optional"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:label"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:filterable"/>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute type="xs:string" name="Name"/>
                        <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:content-version"/>
                    </xs:complexType>
                </xs:element>
                <xs:element name="EntityContainer">
                    <xs:complexType>
                        <xs:sequence>
                            <xs:element name="EntitySet">
                                <xs:complexType>
                                    <xs:simpleContent>
                                        <xs:extension base="xs:string">
                                            <xs:attribute type="xs:string" name="Name"/>
                                            <xs:attribute type="xs:string" name="EntityType"/>
                                            <xs:attribute xmlns:sap="http://www.sap.com/Protocols/SAPData" ref="sap:content-version"/>
                                        </xs:extension>
                                    </xs:simpleContent>
                                </xs:complexType>
                            </xs:element>
                        </xs:sequence>
                        <xs:attribute type="xs:string" name="Name"/>
                        <xs:attribute xmlns:met="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" ref="met:IsDefaultEntityContainer"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
            <xs:attribute type="xs:string" name="Namespace"/>
        </xs:complexType>
    </xs:element>
</xs:schema>