注册XML Schema到ORACLE XDB可以方便生成XML的验证。
What is an XML Schema?
An XML Schema is a language for expressing constraints about XML documents. There are several different schema languages in widespread use, but the main ones are Document Type Definitions (DTDs), Relax-NG, Schematron and W3C XSD (XML Schema Definitions). From this page you can find out more about DTDs and W3C XSD, since those are the primary schema languages defined at W3C.
the schema file ("shiporder.xsd"):
解锁xdb帐号,在xdb下注册xsd:
使用DBMS_XMLSCHEMA.REGISTERSCHEMA注册xsd注册到xdb:
其中'XMLDIR'是ORACLE目录对象名,shiporder.xsd文件在这个目录下。
查看注册对象状态:
对于一些schema定义有递归引用,可能报错不能注册成功。参数force设为true强制注册,然后再进行编译。
DBMS_XMLSCHEMA.REGISTERSCHEMA有多种实现,详细说明参见官方文档。
注册之后可以验证xml文件了:
v_xmldoc.schemavalidate对于验证失败的结果抛出异常。