Java use xml schema

Java use xml schema

Topics here cover how to use the Extensible Markup Language (XML) schema processor for Java.

17.1 Introduction to XML Validation

Topics cover the different techniques for XML validation.

17.1.1 Prerequisites for Using the XML Schema Processor for Java

Prerequisites for using the XML schema processor are covered.

This section assumes that you have working knowledge of these technologies:

  • document type definition (DTD) . An XML document type definition (DTD) defines the legal structure of an XML document.
  • XML Schema language . XML Schema defines the legal structure of an XML document.

To learn more about these technologies, consult the XML resources in Related Documents.

17.1.2 Standards and Specifications for the XML Schema Processor for Java

XML Schema is a World Wide Web Consortium (W3C) standard.

Читайте также:  Javascript get textarea content

The Oracle XML Schema processor supports the W3C XML Schema specifications:

Related Topics

17.1.3 XML Validation with DTDs

Document type definition (DTDs) were originally developed for SGML. XML DTDs are a subset of those available in SGML and provide a mechanism for declaring constraints on XML markup. XML DTDs enable the specification of:

  • Which elements can be in your XML documents.
  • The content model of an XML element, that is, whether the element contains only data or has a set of subelements that defines its structure. DTDs can define whether a subelement is optional or mandatory and whether it can occur only once or multiple times.
  • Attributes of XML elements. DTDs can also specify whether attributes are optional or mandatory.
  • Entities that are legal in your XML documents.

An XML DTD is not itself written in XML, but is a context-independent grammar for defining the structure of an XML document. You can declare a DTD in an XML document itself or in a separate file from the XML document.

Validation is the process by which you verify an XML document against its associated DTD, ensuring that the structure, use of elements, and use of attributes are consistent with the definitions in the DTD. Thus, applications that handle XML documents can assume that the data matches the definition.

Using XDK, you can write an application that includes a validating XML parser; that is, a program that parses and validates XML documents against a DTD. Depending on its implementation, a validating parser may:

  • Either stop processing when it encounters an error, or continue.
  • Either report warnings and errors as they occur or in summary form at the end of processing.
  • Enable or disable validation mode Most processors can enable or disable validation mode, but they must still process entity definitions and other constructs of DTDs.
17.1.3.1 DTD Samples in XDK

An example DTD is shown, together with an example XML document that conforms to that DTD.

Example 17-1 shows the contents of a DTD named family.dtd , which is located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The tags specify the legal nomenclature and structure of elements in the document, whereas the tags specify the legal attributes of elements.

Example 17-2 shows the contents of an XML document named family.xml , which is also located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The element in family.xml specifies that this XML document conforms to the external DTD named family.dtd .

Источник

Java use xml schema

Topics here cover how to use the Extensible Markup Language (XML) schema processor for Java.

18.1 Introduction to XML Validation

Topics cover the different techniques for XML validation.

18.1.1 Prerequisites for Using the XML Schema Processor for Java

Prerequisites for using the XML schema processor are covered.

This section assumes that you have working knowledge of these technologies:

  • document type definition (DTD) . An XML document type definition (DTD) defines the legal structure of an XML document.
  • XML Schema language . XML Schema defines the legal structure of an XML document.

To learn more about these technologies, consult the XML resources in Related Documents.

18.1.2 Standards and Specifications for the XML Schema Processor for Java

XML Schema is a World Wide Web Consortium (W3C) standard.

The Oracle XML Schema processor supports the W3C XML Schema specifications:

Related Topics

18.1.3 XML Validation with DTDs

Document type definition (DTDs) were originally developed for SGML. XML DTDs are a subset of those available in SGML and provide a mechanism for declaring constraints on XML markup. XML DTDs enable the specification of:

  • Which elements can be in your XML documents.
  • The content model of an XML element, that is, whether the element contains only data or has a set of subelements that defines its structure. DTDs can define whether a subelement is optional or mandatory and whether it can occur only once or multiple times.
  • Attributes of XML elements. DTDs can also specify whether attributes are optional or mandatory.
  • Entities that are legal in your XML documents.

An XML DTD is not itself written in XML, but is a context-independent grammar for defining the structure of an XML document. You can declare a DTD in an XML document itself or in a separate file from the XML document.

Validation is the process by which you verify an XML document against its associated DTD, ensuring that the structure, use of elements, and use of attributes are consistent with the definitions in the DTD. Thus, applications that handle XML documents can assume that the data matches the definition.

Using XDK, you can write an application that includes a validating XML parser; that is, a program that parses and validates XML documents against a DTD. Depending on its implementation, a validating parser may:

  • Either stop processing when it encounters an error, or continue.
  • Either report warnings and errors as they occur or in summary form at the end of processing.
  • Enable or disable validation mode Most processors can enable or disable validation mode, but they must still process entity definitions and other constructs of DTDs.
18.1.3.1 DTD Samples in XDK

An example DTD is shown, together with an example XML document that conforms to that DTD.

Example 18-1 shows the contents of a DTD named family.dtd , which is located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The tags specify the legal nomenclature and structure of elements in the document, whereas the tags specify the legal attributes of elements.

Example 18-2 shows the contents of an XML document named family.xml , which is also located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The element in family.xml specifies that this XML document conforms to the external DTD named family.dtd .

Источник

Java use xml schema

Topics here cover how to use the Extensible Markup Language (XML) schema processor for Java.

17.1 Introduction to XML Validation

Topics cover the different techniques for XML validation.

17.1.1 Prerequisites for Using the XML Schema Processor for Java

Prerequisites for using the XML schema processor are covered.

This section assumes that you have working knowledge of these technologies:

  • document type definition (DTD) . An XML document type definition (DTD) defines the legal structure of an XML document.
  • XML Schema language . XML Schema defines the legal structure of an XML document.

To learn more about these technologies, consult the XML resources in Related Documents.

17.1.2 Standards and Specifications for the XML Schema Processor for Java

XML Schema is a World Wide Web Consortium (W3C) standard.

The Oracle XML Schema processor supports the W3C XML Schema specifications:

Related Topics

17.1.3 XML Validation with DTDs

Document type definition (DTDs) were originally developed for SGML. XML DTDs are a subset of those available in SGML and provide a mechanism for declaring constraints on XML markup. XML DTDs enable the specification of:

  • Which elements can be in your XML documents.
  • The content model of an XML element, that is, whether the element contains only data or has a set of subelements that defines its structure. DTDs can define whether a subelement is optional or mandatory and whether it can occur only once or multiple times.
  • Attributes of XML elements. DTDs can also specify whether attributes are optional or mandatory.
  • Entities that are legal in your XML documents.

An XML DTD is not itself written in XML, but is a context-independent grammar for defining the structure of an XML document. You can declare a DTD in an XML document itself or in a separate file from the XML document.

Validation is the process by which you verify an XML document against its associated DTD, ensuring that the structure, use of elements, and use of attributes are consistent with the definitions in the DTD. Thus, applications that handle XML documents can assume that the data matches the definition.

Using XDK, you can write an application that includes a validating XML parser; that is, a program that parses and validates XML documents against a DTD. Depending on its implementation, a validating parser may:

  • Either stop processing when it encounters an error, or continue.
  • Either report warnings and errors as they occur or in summary form at the end of processing.
  • Enable or disable validation mode Most processors can enable or disable validation mode, but they must still process entity definitions and other constructs of DTDs.
17.1.3.1 DTD Samples in XDK

An example DTD is shown, together with an example XML document that conforms to that DTD.

Example 17-1 shows the contents of a DTD named family.dtd , which is located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The tags specify the legal nomenclature and structure of elements in the document, whereas the tags specify the legal attributes of elements.

Example 17-2 shows the contents of an XML document named family.xml , which is also located in $ORACLE_HOME/xdk/demo/java/parser/common/ . The element in family.xml specifies that this XML document conforms to the external DTD named family.dtd .

Источник

Generate Java Code from XML Schema

This topic describes how to get a Java representation of an XML Schema, which involves mapping the elements of the XML Schema to members of a Java class. With IntelliJ IDEA, this transformation can be done using one of the following data binders:

  • JAXB generates classes and groups them in Java packages. A package consists of a Java class name and an ObjectFactory class. The latter is a factory that is used to return instances of a bound Java class.
  • XMLBeans converts an XML Schema into a Java class, compiles it, and places in the specified output jar file.

Generate a Java class from an XML Schema using JAXB

  1. In the active editor tab, open the desired Schema .xsd file or an XML document, which contains the desired Schema.
  2. In the main menu, go to Tools | XML Actions | Generate Java Code From XML Schema Using JAXB .
  3. In the Generate Java from Xml Schema using JAXB dialog, configure the generation procedure:
    • In the Schema/DTD/WSDL Path list, specify the file to be used as the basis for code generation. By default, the field shows the full path to the current file. Accept this suggestion or click Browse and select the desired file in the Select XML Schema File for JAXB Generation that opens.
    • From the Output Path list, select the module source directory to place the generated Java class in.
    • In the Package Prefix list, specify the package to include the generated stubs in.
    • Using the checkboxes, configure additional options, such as generating annotation, setting the read-only status, downloading and installing additional libraries.

Generate and compile a Java class from an XML Schema using XMLBeans

  1. In the active editor tab, open the desired Schema .xsd file or an XML document, which contains the desired Schema.
  2. In the main menu, go to Tools | XML Actions | Generate Java Code From XML Schema Using XmlBeans .
  3. In the Generate Java Code From XML Schema using XMLBeans dialog, configure the generation procedure:
    • In the Schema Path list, specify the file to be used as the basis for code generation. By default, the field shows the full path to the current file. Accept this suggestion or click Browse and select the desired file in the Select XML Schema /WSDL File for Generation dialog that opens.
    • In the Output Path list, specify the name of the jar file to place the generated and compiled Java code in. By default, IntelliJ IDEA suggests creating a new file types.jar . To overwrite an existing file, click Browse and choose the desired file in the Select XML Schema / Wsdl File for generation dialog that opens.
    • To have missing libraries downloaded and installed automatically, select the Add necessary libraries in order for generated code compile and work checkbox.

Источник

Оцените статью