Woodstox : SAX Parsing Using Woodstox with Validation

Overview Woodstox supports SAX parsing with (Document Type Definition) DTD validations. Essentially the structure of XML is validated against the DTD specification. In the following program, we shall explore how to validate an XML document against a DTD by using Woodstox SAX validation capabilitites. Create employeeSchema.xml file as shown below. It describes the elements that … Read more

Woodstox : SAX Parsing Using Woodstox

Overview SAX (Simple API for XML) is an event based parser. The XML document is accessed sequentially and elements of the XML file are handled using callback methods in SAX API. In the following program, we’ll explore how Woodstox provides support for SAX parsing. Create the XML file to be parsed as shown below. It … Read more

Woodstox : java-xml-woodstox-configuration-settings

Overview Woodstox provides numerous settings to control XML processing. A bulk of these settings are available in XMLInputFactory class. A listing of these settings is provided below: Property Details IS_NAMESPACE_AWARE To turn on/off namespace support.This is to support XML 1.0 documents, IS_VALIDATING To turn on/off implementation specific validation IS_COALESCING Requires the parser to coalesce adjacent … Read more

Woodstox : Configuring Woodstox For Low Memory Usage

Overview In certain cases, Woodstox may need to process large XML documents in low memory environment. In such a scenario, Woodstox can be configured to work optimally under low memory condition. In this article, we shall see how to configure woodstox for low memory usage. Create employee.xml as shown below. Create TestConfigurationForLowMemory class as shown … Read more

Woodstox : Configuring Woodstox For High Speed

Overview Woodstox provides various configuration options for efficient performance based on environment constraints. In this article, we shall see how to configure Woodstox for speed assuming that memory is not a significant constraint. Create employee.xml as shown below. Create TestConfigurationForSpeed class as shown below. The configuration for speed is defined using XMLInputFactory2.configureForSpeed() (see line 19 … Read more

Woodstox : Handling Warning Using XMLReporter

Overview This article demonstrates the usage of XMLReporter in handling warning during StAX parsing. Create employee.dtd as shown below. Note that the entity ‘commonAddress’ is defined twice in the DTD (see lines 5-6 below). This will throw a warning condition during parsing. Create employee.xml as shown below. Create TestWarning as shown below. Define a custom … Read more

Woodstox : Exploring Validation Errors Using ValidationProblem

Overview In this article, we shall demonstrate how details of validation error can be obtained by using ValidationProblem class. Create the employee.dtd as shown below. It defines the employee element that contains id, name and salary sub-elements. Create invalidEmployee.xml as shown below. Note that it is not in accordance with employee.dtd described above as it … Read more

Woodstox : Handling Exceptions Related to Mal-Formed XML

Overview In this article, we shall demonstrate handling of exception when XML is not well formed. Create employee.xml as shown below. Note that this XML document is not well-formed e.g. the ‘salary’ end element is not properly closed (see line 4 below). Create TestXmlException class. Note that XMLStreamException is caught and error message is redirected … Read more

Woodstox : Validate XML generated by Woodstox

Overview In this article we shall perform validation of generated XML by XMLStreamWriter . This demonstrates Woodstox’ validation capabilities while generating XML output. Create employee.dtd as shown below. It defines the employee element that contains id, name and salary sub-elements. Create TestValidationXmlStreamWriter as shown below. Create a valid XML as per the DTD as shown … Read more

Woodstox : Validate against RelaxNG Schema

Overview This article demonstrates how to validate an XML document against an RelaxNG Schema by using Woodstox. See relaxng.org’s homepage for further details on RelaxNG XML schema specification. Create employee.rng as shown below. It defines the employee element that contains id, name and salary sub-elements. Create validEmployee.xml as shown below. It is in accordance with … Read more