There was a task of processing a huge number of xml files (> 50mln) for the further splitting of their elements into fields in the database. Chose oracle DB. Schemes are schemes working.

But there was a problem: when importing the scheme, it gives an error in this place

Syntax

With an error:

Error report - ORA-31082: invalid attribute "totalDigits" specified in the declaration of local simple type

But at the same time, for example, such a structure goes bang:

enter image description here

As far as I understand, for some reason he doesn’t like totalDigits, although, judging by the description of totalDigits, the construction is correct. And given that this scheme is a schema from a working database.

May be used as facet for: xs: byte, xs: decimal, xs: int, xs: integer, xs: long, xs: negativeInteger, xs: nonNegativeInteger, xs: nonPositiveInteger, xs: positiveInteger, xs: short, xs: unsignedByte , xs: unsignedInt, xs: unsignedLong, xs: unsignedShort

  • Try typing integer instead of int. And 20 characters are not many? - Bakhuss
  • @Bakhuss tried with integer instead of int - everything also. I also thought that 20 is somehow a lot, since max. Int is a ten-digit number. But what is captivating is that this scheme is a dump from a working database ... - Vladimir Afanasyev
  • Do you and max Int installed? Maybe there is a connection between them, like, totalDigits can not be more than ... and therefore there is an error? - Bakhuss
  • @Bakhuss No, I just put it wrong. The maximum Int value is 2 147 483 648 (10 characters) - Vladimir Afanasyev
  • How do you register the scheme? Could add a question with an example. At the same time, please replace the images with xsd fragments as text. - 0xdb

1 answer 1

The totalDigits totalDigits is quite valid for xs:int . The scheme will be registered with the value value="20" , because base type xs:int itself does not have this facet. But to set this value to more than 10 does not make sense, because xs:int has another limitation:

 maxInclusive="2147483647" minInclusive="-2147483648" 

A viable example:

 declare schemaDoc xmlType := xmlType(' <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:simpleType name="itemId"> <xs:restriction base="xs:int"> <xs:totalDigits value="20"/> </xs:restriction> </xs:simpleType> <xs:complexType name="itemType"> <xs:sequence> <xs:element name="id" type="itemId"/> <xs:element name="name" type="xs:string"/> </xs:sequence> </xs:complexType> <xs:element name="item" type="itemType"/> </xs:schema>'); begin dbms_xmlschema.registerSchema ( schemaurl => 'item.xsd', schemadoc => schemaDoc, local => true, gentypes => false, gentables => false ); dbms_output.put_line ('schema registred'); end; / schema registred 

The schema was successfully registered, but creating instances of XML documents is possible only if the values ​​are within acceptable limits:

 declare xmldoc xmlType := xmlType (' <item xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://xmlns.oracle.com/xdb/schemas/'||user||'/item.xsd"> <id>9999999999</id> <name>my item</name> </item>'); begin xmldoc.schemaValidate (); dbms_output.put_line ('XML validated='|| xmldoc.isSchemaValidated()); end; / 

ORA-31038: Invalid integer value: "9999999999"
31038. 00000 - "Invalid% s value: \"% s \ ""
* Cause: The text in the XML document did not represent a valid
value given the datatype and other constraints in the schema.
* Action: Ensure that XML documents is valid
with respect to datatype and other constraints in the schema.