Oracle Database 10g XML SQL [Electronic resources] : Design, Build Manage XML Applications in Java, C, C++ PL/SQL نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Oracle Database 10g XML SQL [Electronic resources] : Design, Build Manage XML Applications in Java, C, C++ PL/SQL - نسخه متنی

Mark V. Scardina, Ben Chang, Jinyu Wang

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
توضیحات
افزودن یادداشت جدید











Validating XML with XML Schemas (XSDs)

A validating XML parser, by parsing the XML document according to the rules specified in the XML schema, tries to determine whether the document conforms to the XML schema (valid), meaning that the structural relationships and sequences are the same and that conformance to the datatype rules specified in the XML schema are observed. Depending on the implementation of the parser, as with parsers that validate XML documents against DTDs, if an error is encountered during validation, processing may stop (as in “panic mode” exception processing) or continue with internal corrections. Warnings or errors may be reported either as processing occurs or at the very end of the processing. For a validating XML Schema parser, one final requirement is that if a DTD is also included by the XML document and entity definitions are encountered in the DTD, these must be taken into account by the XML schema, along with any other constructs possibly defined in the DTD. However, since the XML Schema specification does not exactly define what occurs if both a DTD and an XML schema exist for an XML document, such a situation is left to the validating parser to determine what exactly to do, which creates an implementation-dependent scenario.

Oracle produces, as part of the XDK, three XML Schema processors, Java, C, and C++, that can perform both DTD and XSD validations. In addition, the Oracle XML DB can perform validation on XML documents as they are inserted or updated. This is built in to the support for XMLType but can also be directly invoked from PL/SQL. Specific code illustrating schema validation will be presented later in the chapter, but it is useful to understand the underlying process model.

Schema validation can be triggered in two ways: external to the input document or as a result of the input document. This means that an XML schema can be passed in when the XML parser is invoked or, if the input document includes an XML Schema declaration providing a URL to the location, the XML schema can be fetched during the process. The following is the syntax of this type of declaration with and without namespaces:

<root xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="[target_namespace] [schemafile_location]">
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="[schemafile_location]">

The schema processor needs not only to build an object of the input document through parsing but also to parse the schema document into an object for the validation process to begin. This is where the different processors depart. For Java, the input and schema documents are parsed using SAX with a DOM built as needed from these SAX events. If validation is only required, then it is completely SAX based. For C and C++ processors, DOM parsing and processing is used throughout the validation process.

The Oracle XML DB, even though it uses the C XDK components, performs this processing quite differently. If it has a registered copy of the XML schema, it has already compiled and stored it as a database object, so no schema parsing is required. Upon inserting a document, the C SAX parser is invoked and the validation occurs against the compiled schema.

In all cases, if the XML schema has one or more <xsd:import> or <xsd:include> elements, as illustrated next, they will be retrieved and expanded into one aggregated schema before any validation occurs.

<xsd:import namespace=http://www.w3schools.com/schema
schemaLocation="http://www.w3schools.com/schema/customer.xsd"/>
<xsd:include schemaLocation="http://www.w3schools.com/schema/customer.xsd"/>

/ 218