XML validation against an XSD fails in Oracle but it gets validated in XMLSpy
XSD is registered in oracle. Using XMLTYPE.schemavalidate to validate an XML against the registered XSD. The API gives an error as "LSX-00295: field element "item" is开发者_如何学运维 not a simple type". But the same XML file with the same XSD gets validated fine in Altova XMLSpy. Somehow oracle is giving the complex type error.
Anonymous script is as below:
declare
lxml XMLTYPE;
l_err varchar2(4000);
l_transformxml CLOB:='<?xml version="1.0" encoding="UTF-8"?>
<tdvpf:products numproducts="2" xsi:schemaLocation="http://www.techdata.com/vpf VendorPriceFileTemplate_Volume.xsd" xmlns:tdvpf="http://www.techdata.com/vpf" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<product>
<base>
<distributorsku numitems="1">
<item index="2">a</item>
</distributorsku>
<vendor numitems="1">
<item index="2">a</item>
</vendor>
<vendorpartnumber numitems="1">
<item index="2">a</item>
</vendorpartnumber>
<endusertype numitems="1">
<item index="2">Government</item>
</endusertype>
<endusersubtype numitems="1">
<item index="2">a</item>
</endusersubtype>
<vendorproductgroup numitems="1">
<item index="2">a</item>
</vendorproductgroup>
<productname numitems="1">
<item index="2">a</item>
</productname>
<productdescription numitems="1">
<item index="2">a</item>
</productdescription>
<cost numitems="1">
<item index="2">0.0</item>
</cost>
<msrp numitems="1">
<item index="2">0.0</item>
</msrp>
<operatingsystem numitems="1">
<item index="2">Linux</item>
</operatingsystem>
<operatingsystemversion numitems="1">
<item index="2">a</item>
</operatingsystemversion>
<platform numitems="1">
<item index="2">64 bit</item>
</platform>
<version numitems="1">
<item index="2">a</item>
</version>
<edition numitems="1">
<item index="2">a</item>
</edition>
<licensetype numitems="1">
<item index="2">a</item>
</licensetype>
<licenseduration numitems="1">
<item index="2">a</item>
</licenseduration>
<packagetype numitems="1">
<item index="2">Full package product</item>
</packagetype>
<mediatype numitems="1">
<item index="2">a</item>
</mediatype>
<maintenancesupporttype numitems="1">
<item index="2">a</item>
</maintenancesupporttype>
<maintenancesupportduration numitems="1">
<item index="2">a</item>
</maintenancesupportduration>
<licenseprogram numitems="1">
<item index="2">a</item>
</licenseprogram>
<language numitems="1">
<item index="2">a</item>
</language>
<productclass numitems="1">
<item index="2">Applications</item>
</productclass>
<mediapartnumber numitems="1">
<item index="2">a</item>
</mediapartnumber>
<requireditems numitems="1">
<item index="2">a</item>
</requireditems>
<seats-qty numitems="1">
<item index="2">a</item>
</seats-qty>
<users-qty numitems="1">
<item index="2">a</item>
</users-qty>
<appliances-qty numitems="1">
<item index="2">a</item>
</appliances-qty>
<devices-qty numitems="1">
<item index="2">a</item>
</devices-qty>
<migrations-qty numitems="1">
<item index="2">a</item>
</migrations-qty>
<mailboxes-qty numitems="1">
<item index="2">a</item>
</mailboxes-qty>
<gigabytes-qty numitems="1">
<item index="2">a</item>
</gigabytes-qty>
<servers-qty numitems="1">
<item index="2">a</item>
</servers-qty>
<workstations-qty numitems="1">
<item index="2">a</item>
</workstations-qty>
<licenses-qty numitems="1">
<item index="2">a</item>
</licenses-qty>
<processors-qty numitems="1">
<item index="2">a</item>
</processors-qty>
<domains-qty numitems="1">
<item index="2">a</item>
</domains-qty>
<nodes-qty numitems="1">
<item index="2">a</item>
</nodes-qty>
</base>
<licenseprogram>
<points numitems="1">
<item index="2">0.0</item>
</points>
<minquantity numitems="1">
<item index="2">0.0</item>
</minquantity>
<maxquantity numitems="1">
<item index="2">0.0</item>
</maxquantity>
<volumelevel numitems="1">
<item index="2">a</item>
</volumelevel>
<groupmethod numitems="1">
<item index="2">ProgramPool</item>
</groupmethod>
</licenseprogram>
</product>
</tdvpf:products>
';
begin
lxml := XMLTYPE (l_transformxml).createschemabasedxml ('VendorPriceFileTemplate_Volume.xsd');
XMLTYPE.schemavalidate (lxml);
IF lxml.isschemavalid () = 1
THEN
DBMS_OUTPUT.put_line ('XSD validation success');
END IF;
EXCEPTION
WHEN OTHERS
THEN
l_err := SUBSTR (SQLERRM, 1, 4000);
DBMS_OUTPUT.put_line ('Error: ' || l_err);
END;
Apparently the schema defines item
as an element with a simpleType, which means it cannot contain attributes.
<item index="2">a</item>
精彩评论