Home » Developer & Programmer » JDeveloper, Java & XML » xml global element validation (Oracle 12c)
xml global element validation [message #679070] Fri, 31 January 2020 03:44
sss111ind
Messages: 636
Registered: April 2012
Location: India
Senior Member

Hi All,

The xml parsing is not getting failed even if I do not include FileDetails(global element node).The correct XML must have all the nodes as follows,

--xml file original
<FileDetails>
	<TransactionDetails>
		<SR_NUMBER>12344</SR_NUMBER> 
		<CUSTOMER_CODE>201800123</CUSTOMER_CODE>
		<CUSTOMER_NAME>NIPPON</CUSTOMER_NAME>        
	</TransactionDetails>
</FileDetails>

--registering xsd
 DECLARE
  l_schema  CLOB;
BEGIN

  l_schema := '<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

<!-- definition of simple elements -->
<xs:element name="SR_NUMBER" type="xs:string"/>
<xs:element name="CUSTOMER_CODE" type="xs:string"/>
<xs:element name="CUSTOMER_NAME" type="xs:string"/>

<!-- definition of attributes -->

<!-- definition of complex elements -->
<xs:element name="TransactionDetails">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="SR_NUMBER"/>      
      <xs:element ref="CUSTOMER_CODE"/>
      <xs:element ref="CUSTOMER_NAME"/>
    </xs:sequence>
  </xs:complexType>
</xs:element>

<xs:element name="FileDetails">
  <xs:complexType>
    <xs:sequence>
      <xs:element ref="TransactionDetails" maxOccurs="unbounded"/>    
    </xs:sequence>    
  </xs:complexType>
</xs:element>

</xs:schema>';

   DBMS_XMLSCHEMA.registerSchema(schemaurl       => 'my_schema.xsd', 
                                 schemadoc       => l_schema,
                                 local           => TRUE,
                                 gentypes        => FALSE,
                                 gentables       => FALSE,
                                 enablehierarchy => DBMS_XMLSCHEMA.enable_hierarchy_none); 

END;
/

--validating xml but no error even FileDetails is not included
DECLARE
  l_xml      CLOB;
  l_xmltype  XMLTYPE;
BEGIN

  l_xml := '<?xml version="1.0" encoding="UTF-8" standalone="no"?>
	<TransactionDetails>
		<SR_NUMBER>12344</SR_NUMBER> 
		<CUSTOMER_CODE>201800123</CUSTOMER_CODE>
		<CUSTOMER_NAME>NIPPON</CUSTOMER_NAME>        
	</TransactionDetails>
';

  l_xmltype := XMLTYPE(l_xml, 'my_schema.xsd');
  l_xmltype.schemavalidate;

END;
/


--for deleting if required 
begin
DBMS_XMLSCHEMA.DELETESCHEMA(
   'my_schema1.xsd');
   end;
   
Thank you.
Previous Topic: ORA-29532: Java call terminated by uncaught Java exception: java.lang.AbstractMethodError
Next Topic: Applet build error - Array index out of range
Goto Forum:
  


Current Time: Sat Nov 23 03:27:50 CST 2024