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

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
主站蜘蛛池模板: 邵东县| 灵宝市| 西乌珠穆沁旗| 米泉市| 中江县| 青阳县| 裕民县| 枣庄市| 吉木乃县| 思茅市| 营口市| 泗洪县| 钟山县| 霍林郭勒市| 裕民县| 宜阳县| 山丹县| 大石桥市| 郸城县| 平凉市| 高清| 西青区| 明水县| 吉水县| 厦门市| 伊金霍洛旗| 铁力市| 昭苏县| 壶关县| 肇源县| 大港区| 东乡族自治县| 宝丰县| 建瓯市| 东丽区| 华池县| 天等县| 东台市| 镇雄县| 紫金县| 屏南县|