【问题标题】:Generate XSD File from an XML with xmltype in Oracle PL/SQL在 Oracle PL/SQL 中使用 xmltype 从 XML 生成 XSD 文件
【发布时间】:2017-01-01 07:13:35
【问题描述】:

我想要的结果是在 oracle 中直接从 XML 生成 XSD 文件

我在 PL/SQL 过程中使用 SQL 查询从表中生成 XMLType。

然后我使用该 XMLtype 执行 .GetClobVal() 并返回我当前复制到以下在线工具中的 clob 版本 http://www.freeformatter.com/xsd-generator.html 然后能够从中生成 XSD。

我知道这个 XSD 并不完美,也不会完全符合我的要求,但它非常接近。

我想知道是否有人知道Oracle中可以做到这一点的工具,我只能找到generating XSD from an Oracle type,但在这种情况下我不使用Oracle类型,所以请不要建议使用一个

这是我用来创建 xml 的代码示例

With  Accounts As  (  Select  XMLAgg(
                              XMLElement("AccountDetail",
                                XMLForest(1234    || Level  As "UID",
                                          'Test'  || Level  As "Name"))) As xmlData,
                              Count(*) as dataCount
                      From    Dual
                      Connect By Level <= 2
               )
Select  XMLElement("GetAccountDataResponse",
          XMLElement("ResponseInfo",
            XMLElement("Code",            'Success'),
            XMLElement("Message",         'Normal Successful Completion'),
            XMLElement("DebugInfo",
              XMLElement("DBVersion",     'V01.01.00'))),
            Accounts.xmlData
        ).GetClobVal()
From    Accounts;

这是 XML 示例:

<GetAccountDataResponse>
  <ResponseInfo>
    <Code>Success</Code>
    <Message>Normal Successful Completion</Message>
    <DebugInfo>
      <DBVersion>V01.01.00</DBVersion>
    </DebugInfo>
  </ResponseInfo>
  <AccountDetail>
    <UID>12341</UID>
    <Name>Test1</Name>
  </AccountDetail>
  <AccountDetail>
    <UID>12342</UID>
    <Name>Test2</Name>
  </AccountDetail>
</GetAccountDataResponse>

当您将代码复制到我之前提到的 xsd-generator 中时,您会得到以下输出:

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="GetAccountDataResponse">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="ResponseInfo">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:string" name="Code"/>
              <xs:element type="xs:string" name="Message"/>
              <xs:element name="DebugInfo">
                <xs:complexType>
                  <xs:sequence>
                    <xs:element type="xs:string" name="DBVersion"/>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
        <xs:element name="AccountDetail" maxOccurs="unbounded" minOccurs="0">
          <xs:complexType>
            <xs:sequence>
              <xs:element type="xs:short" name="UID"/>
              <xs:element type="xs:string" name="Name"/>
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>

这非常接近,可以让我在 PL/SQL 等中将 type="xs:short" 替换为 type="xs:int" 以获得我想要的输出。

如果有一个 JAVA 程序可以做到这一点,我也会很高兴,因为 Oracle 支持本地运行 JAVA

【问题讨论】:

  • 有谁能帮忙吗?

标签: java xml oracle plsql xsd


【解决方案1】:

没有从 XML 生成 XSD 的 Oracle 工具。

你可以试试这个 Apache XMLBeans inst2xsd 工具:http://xmlbeans.apache.org/docs/2.0.0/guide/tools.html#inst2xsd

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-12-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-25
    相关资源
    最近更新 更多