官术网_书友最值得收藏!

JDeveloper built-in schema validation

Oracle JDeveloper 11g has built-in support for XML schema validation. If an XML document includes a reference to an XML schema, the XML document may be validated with the XML schema using the built-in feature. An XML schema may be specified in an XML document using the xsi:noNamespaceSchemaLocation attribute or the xsi:namespaceSchemaLocation attribute. Before we discuss when to use which attribute, we need to define the target namespace. A schema is a collection of type definitions and element declarations whose names belong to a particular namespace called a target namespace. Thus, a target namespace distinguishes between type definitions and element declarations from different collections. An XML schema doesn't need to have a target namespace. If the XML schema has a target namespace, specify the schema's location in an XML document using the xsi:namespaceSchemaLocation attribute. If the XML schema does not have a target namespace, specify the schema location using the xsi:noNamespaceSchemaLocation attribute. The xsi:noNamespaceSchemaLocation and xsi:namespaceSchemaLocation attributes are a hint to the processor about the location of an XML schema document. Taking the example XML schema catalog.xsd and the example XML document, catalog.xml from the previous chapter, specify the XML schema location in the XML document using the following attribute declaration:

xsi:noNamespaceSchemaLocation="catalog.xsd"

The XML schema may be in any directory. The example XML document does not include any namespace elements. Therefore, the schema is specified with the xsi:noNamespaceSchemaLocation attribute in the root element catalog. The XML schema may be specified with a relative URL, or a file, or an HTTP URL. The xsi:noNamespaceSchemaLocation attribute we added specifies the relative path to the XML schema document catalog.xsd. To validate the XML document with the XML schema, right-click on the XML document and select Validate XML.

JDeveloper built-in schema validation

The XML document gets validated with the XML schema and the output indicates that the XML document does not have any validation errors.

JDeveloper built-in schema validation

To demonstrate validation errors, add a non-valid element to the XML document. As an example, add the following element to the catalog element after the first journal element:

<article></article>

To validate the modified XML document, right-click on the XML document and select Validate XML. The output indicates validation errors. All the elements after the non-valid element become non-valid. For example, the journal element is valid as a subelement of the catalog element, but because the second journal element is after the non-valid article element, the journal element also becomes non-valid as indicated in the validation output.

JDeveloper built-in schema validation
主站蜘蛛池模板: 开阳县| 扎赉特旗| 云南省| 阜宁县| 鄂伦春自治旗| 义乌市| 宜宾县| 淄博市| 澜沧| 晴隆县| 周宁县| 波密县| 乌兰浩特市| 隆尧县| 壤塘县| 天台县| 晴隆县| 新疆| 兴和县| 屯昌县| 文安县| 嵊泗县| 灌阳县| 刚察县| 太谷县| 朝阳市| 诏安县| 彭山县| 普定县| 久治县| 遂宁市| 龙州县| 梅州市| 定襄县| 沙雅县| 班玛县| 新邵县| 太和县| 涞水县| 昌吉市| 安阳县|