简体   繁体   English

在XMLSCHEMA中创建父节点

[英]Create parent node in XMLSCHEMA

Have objects: 有对象:

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
)
/

create simple xml schema: 创建简单的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;
/

test generation xml by object: 按对象测试生成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;

get this xml: 得到这个XML:

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

LIST on same level as OBJ1, OBJ2. 清单与OBJ1,OBJ2处于同一级别。 Is there any way to change XMLSCHEMA to create parent node to LIST to create xml like: 有什么办法可以将XMLSCHEMA创建父节点更改为LIST创建xml,例如:

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

Create a new complexType named LISTType : 创建一个名为LISTType的新complexType

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM