在XMLSCHEMA

时间:2017-07-25 11:16:09

标签: xml oracle schema

有对象:

create or replace type test.type_numberlist as table of number;
/

create or replace type test.type_test as object (
    LIST  test.type_numberlist
  , OBJ1  number
  , OBJ2  number
)
/

创建简单的xml架构:

BEGIN DBMS_XMLSCHEMA.registerSchema(
  SCHEMAURL => 'testschema.xsd',
  SCHEMADOC => '<?xml version="1.0"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xmlns:xdb="http://xmlns.oracle.com/xdb"
            xsi:schemaLocation="http://xmlns.oracle.com/xdb http://xmlns.oracle.com/xdb/XDBSchema.xsd">
  <xsd:element name="document" type="TYPE_TESTType" xdb:SQLType="TYPE_TEST" xdb:SQLSchema="TEST"/>
  <xsd:complexType name="TYPE_TESTType" xdb:SQLType="TYPE_TEST" xdb:SQLSchema="TEST" xdb:maintainDOM="false">
  <xsd:sequence>
   <xsd:element name="LIST" type="xsd:double" maxOccurs="unbounded" minOccurs="0" xdb:SQLName="LIST" xdb:SQLCollType="TYPE_NUMBERLIST" xdb:SQLType="NUMBER" xdb:SQLCollSchema="TEST"/>
   <xsd:element name="OBJ1" type="xsd:double" xdb:SQLName="OBJ1" xdb:SQLType="NUMBER"/>
   <xsd:element name="OBJ2" type="xsd:double" xdb:SQLName="OBJ2" xdb:SQLType="NUMBER"/>
  </xsd:sequence>
 </xsd:complexType>
</xsd:schema>',
   LOCAL     => FALSE, 
   GENTYPES  => FALSE,
   OWNER     => 'TEST'); 
END;
/

按对象测试生成xml:

declare 
  i test.type_test := new test.type_test(LIST => test.type_numberlist(1,2)
                                        ,OBJ1 => 1
                                        ,OBJ2 => 2);
  v_xml xmltype;
begin
  v_xml := xmltype( xmlData => i
                  , schema => 'TESTSCHEMA.xsd'
                  , element => 'document'
                  , validated => 1);
  dbms_output.put_line(v_xml.getstringval());
end;

获取此xml:

<document>
  <LIST>1</LIST>
  <LIST>2</LIST>
  <OBJ1>1</OBJ1>
  <OBJ2>2</OBJ2>
</document>

与OBJ1,OBJ2处于同一级别的列表。是否有任何方法可以更改XMLSCHEMA以创建父节点到LIST以创建xml,如:

<document>
  <LIST>
    <value>1</value>
    <value>2</value>
  </LIST>
  <OBJ1>1</OBJ1>
  <OBJ2>2</OBJ2>
</document>

1 个答案:

答案 0 :(得分:0)

创建名为complexType的新LISTType

<xsd:complexType name="LISTType" xdb:maintainDOM="false" xdb:SQLType="TYPE_NUMBERLIST" >
    <xsd:sequence>
        <xsd:element name="VALUE" type="xsd:double" maxOccurs="unbounded" minOccurs="0" xdb:SQLType="NUMBER"/>
    </xsd:sequence>
</xsd:complexType>
<xsd:element name="document" type="TYPE_TESTType" xdb:SQLType="TYPE_TEST" xdb:SQLSchema="TEST"/>
<xsd:complexType name="TYPE_TESTType" xdb:SQLType="TYPE_TEST" xdb:SQLSchema="TEST" xdb:maintainDOM="false">
    <xsd:sequence>
        <xsd:element name="LIST" xdb:SQLCollType="TYPE_NUMBERLIST" xdb:SQLCollSchema="TEST"/>
        <xsd:element name="OBJ1" type="xsd:double" xdb:SQLName="OBJ1" xdb:SQLType="NUMBER"/>
        <xsd:element name="OBJ2" type="xsd:double" xdb:SQLName="OBJ2" xdb:SQLType="NUMBER"/>
    </xsd:sequence>
 </xsd:complexType>