Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
XML Schema Validaiton with dom\Writer.java
How to perform XML Schema validation with dom\Writer.java provided in the Apache Xerces package?
✍: FYIcenter
You can perform XML Schema validation with the dom\Writer.java program
provided in the Apache Xerces package as shown below.
Run the dom\Writer.java program with "-v -s" option to turn on XML Schema validation. If the input XML file does not meet the requirements of its Schema, you will see validation errors:
\fyicenter\xerces-2_11_0\samples>\fyicenter\jdk-1.8.0\bin\java
-cp .;..\xercesSamples.jar;..\xercesImpl.jar;..\xml-apis.jar
dom.Writer -v -s UserXsdError.xml
[Error] UserXsdError.xml:6:25: cvc-datatype-valid.1.2.1: 'ONE' is not a valid value for 'integer'.
[Error] UserXsdError.xml:6:25: cvc-type.3.1.3: The value 'ONE' of element 'fyi:ID' is not valid.
[Error] UserXsdError.xml:8:52: cvc-datatype-valid.1.2.1: '1970-01-01+00:01' is not a valid value for 'dateTime'.
[Error] UserXsdError.xml:8:52: cvc-type.3.1.3: The value '1970-01-01+00:01' of element 'fyi:BirthDate' is not valid.
<?xml version="1.0" encoding="UTF-8"?>
<fyi:User xmlns:fyi="http://fyicenter.com" xmlns:xsi="http://www.w3.org/2001/XML
Schema-instance" xsi:schemaLocation="http://fyicenter.com User.xsd">
<fyi:ID>ONE</fyi:ID>
<fyi:Name>Frank Y. Ivy</fyi:Name>
<fyi:BirthDate>1970-01-01+00:01</fyi:BirthDate>
<fyi:Sex>Male</fyi:Sex>
</fyi:User>
The XML file used in the above test is, UserXsdError.xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) 2017 FYIcenter.com -->
<fyi:User xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:fyi="http://fyicenter.com"
xsi:schemaLocation="http://fyicenter.com User.xsd">
<fyi:ID>ONE</fyi:ID>
<fyi:Name>Frank Y. Ivy</fyi:Name>
<fyi:BirthDate>1970-01-01+00:01</fyi:BirthDate>
<fyi:Sex> Male</fyi:Sex>
</fyi:User>
The XML Schema file used in the above test is, User.xsd:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!-- Copyright (c) 2017 FYIcenter.com -->
<xsd:schema
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:fyi="http://fyicenter.com"
targetNamespace="http://fyicenter.com"
elementFormDefault="qualified">
<xsd:element name="User">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="ID" type="xsd:integer"/>
<xsd:element name="Name" type="xsd:string"/>
<xsd:element name="BirthDate" type="xsd:dateTime"/>
<xsd:element name="Sex" type="fyi:sexType"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:simpleType name="sexType">
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="Male"/>
<xsd:enumeration value="Femal"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:schema>
⇒ dom\GetElementsByTagName.java - Apache Xerves DOM Sample
⇐ XML DTD Validaiton with dom\Writer.java
2017-11-11, ≈39🔥, 0💬
Popular Posts:
JDK 17 jdk.internal.vm.ci.jmod is the JMOD file for JDK 17 Internal VM CI module. JDK 17 Internal VM...
JDK 11 jdk.scripting.nashorn.jm odis the JMOD file for JDK 11 Scripting Nashorn module. JDK 11 Scrip...
Where to get the Java source code for Connector/J 8.0 Core API module? Java source code files for Co...
commons-net-1.4.1.jar is the JAR file for Apache Commons Net 1.4.1, which implements the client side...
What JAR files are required to run dom\Counter.java provided in the Apache Xerces package? You can f...