# xerces **Repository Path**: mirrors_codelibs/xerces ## Basic Information - **Project Name**: xerces - **Description**: xerces for Java 11 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2020-08-08 - **Last Updated**: 2026-03-21 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Xerces2-J A high-performance, fully compliant XML parser implementing XML 1.0/1.1, XML Schema 1.0, DOM Level 3, XInclude, JAXP, SAX, and StAX APIs. This is a fork maintained by [CodeLibs](https://www.codelibs.org/) based on Apache Xerces. ## ๐Ÿš€ Key Features - **Complete XML Support**: XML 1.0 and XML 1.1 specification compliance - **Schema Validation**: Full XML Schema 1.0 processor with experimental 1.1 support - **Multiple APIs**: DOM Level 3 Core/Load/Save, SAX, StAX, JAXP integration - **XInclude Support**: Complete XML Inclusions (XInclude) W3C Recommendation implementation - **Modular Architecture**: Xerces Native Interface (XNI) for building custom parser components - **High Performance**: Optimized for speed and memory efficiency - **Standards Compliant**: Reference implementation quality with comprehensive test suite ## ๐Ÿ›  Tech Stack - **Java**: 17+ (compiled with release flag for compatibility) - **Build System**: Apache Maven 3.x - **Testing**: JUnit 5 with Vintage engine for backward compatibility - **Dependencies**: XML Resolver (optional) ## ๐Ÿ“‹ Prerequisites - **JDK 17 or higher** - Required for building and running - **Apache Maven 3.x** - For build management - **Git** - For source code management ## โšก Quick Start ### Installation ```bash # Clone the repository git clone https://github.com/codelibs/xerces.git cd xerces # Build the project mvn clean install # Skip tests for faster build mvn clean install -DskipTests ``` ### Maven Dependency Add to your `pom.xml`: ```xml org.codelibs.xerces xerces 3.0.0-SNAPSHOT ``` ## ๐Ÿ”ง Build Commands ### Core Build Operations ```bash # Compile source code mvn compile # Build JAR file mvn package # Run all tests (433 tests) mvn test # Generate Javadocs mvn javadoc:javadoc # Clean build artifacts mvn clean # Complete build with tests mvn clean install ``` ### Development Commands ```bash # Format code according to CodeLibs standards mvn formatter:format # Generate test coverage report mvn jacoco:report # Check license headers mvn license:check # Update license headers mvn license:format ``` ### Deployment ```bash # Deploy to Maven Central (requires proper credentials) ./deploy.sh ``` ## ๐Ÿ“– Usage Examples ### Basic XML Parsing with DOM ```java import org.codelibs.xerces.parsers.DOMParser; import org.w3c.dom.Document; DOMParser parser = new DOMParser(); parser.parse("example.xml"); Document document = parser.getDocument(); ``` ### SAX Parsing ```java import org.codelibs.xerces.parsers.SAXParser; import org.xml.sax.helpers.DefaultHandler; SAXParser parser = new SAXParser(); parser.setContentHandler(new DefaultHandler() { @Override public void startElement(String uri, String localName, String qName, Attributes attributes) { System.out.println("Element: " + qName); } }); parser.parse("example.xml"); ``` ### XML Schema Validation ```java import org.codelibs.xerces.parsers.DOMParser; import org.codelibs.xerces.impl.Constants; DOMParser parser = new DOMParser(); parser.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true); parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, true); parser.parse("document.xml"); ``` ### XInclude Processing ```java import org.codelibs.xerces.parsers.XIncludeParserConfiguration; import org.codelibs.xerces.parsers.DOMParser; XIncludeParserConfiguration config = new XIncludeParserConfiguration(); DOMParser parser = new DOMParser(config); parser.parse("document-with-xincludes.xml"); ``` ## ๐Ÿ— Project Structure ``` src/main/java/org/codelibs/xerces/ โ”œโ”€โ”€ parsers/ # High-level parser implementations โ”œโ”€โ”€ impl/ # Core parser implementation โ”‚ โ”œโ”€โ”€ dtd/ # DTD validation โ”‚ โ”œโ”€โ”€ dv/ # Datatype validation (Schema) โ”‚ โ”œโ”€โ”€ xs/ # XML Schema processing โ”‚ โ”œโ”€โ”€ xpath/ # XPath subset for Schema โ”‚ โ””โ”€โ”€ validation/ # Validation framework โ”œโ”€โ”€ xni/ # Xerces Native Interface (XNI) โ”œโ”€โ”€ dom/ # DOM Level 3 implementation โ”œโ”€โ”€ jaxp/ # JAXP API integration โ”œโ”€โ”€ stax/ # StAX API integration โ”œโ”€โ”€ util/ # Utility classes โ”œโ”€โ”€ xinclude/ # XInclude processing โ””โ”€โ”€ xs/ # XML Schema API ``` ### Sample Code The project includes comprehensive examples in `src/sample/java/`: - **SAX Examples**: Event-driven parsing - **DOM Examples**: Tree-based document manipulation - **JAXP Examples**: Standard Java API usage - **XNI Examples**: Low-level parser component usage - **Schema Examples**: Validation and type information access ## ๐Ÿงช Testing The project includes 433 comprehensive tests covering: - **Core Parser Functionality**: XML 1.0/1.1 parsing - **Schema Validation**: XML Schema 1.0 compliance - **API Compatibility**: SAX, DOM, StAX, JAXP integration - **XInclude Processing**: Inclusion mechanism testing - **Performance Tests**: Memory and speed benchmarks ```bash # Run all tests mvn test # Run with coverage report mvn clean test jacoco:report # View coverage report open target/site/jacoco/index.html ``` ## ๐Ÿ”ง Configuration Options ### Parser Features ```java // Enable schema validation parser.setFeature("http://apache.org/xml/features/validation/schema", true); // Enable XInclude processing parser.setFeature("http://apache.org/xml/features/xinclude", true); // Set security features parser.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true); ``` ### System Properties ```bash # Enable schema validation by default -Dorg.codelibs.xerces.xni.parser.XMLParserConfiguration=org.codelibs.xerces.parsers.XML11Configuration # Set entity resolver -Dorg.xml.sax.driver=org.codelibs.xerces.parsers.SAXParser ``` ## ๐Ÿš€ Performance Xerces2-J is optimized for: - **High Throughput**: Efficient XML parsing for large documents - **Low Memory Footprint**: Minimal memory usage during processing - **Scalability**: Suitable for high-load server environments - **Compliance**: Full standards compliance without performance sacrifice ## ๐Ÿ› Troubleshooting ### Common Issues **OutOfMemoryError during large document parsing:** ```bash # Increase heap size export MAVEN_OPTS="-Xmx2g" mvn test ``` **Schema validation not working:** ```java // Ensure both validation and schema features are enabled parser.setFeature(Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE, true); parser.setFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE, true); ``` **Build failures on Java 17+:** ```bash # Ensure JAVA_HOME points to JDK 17+ export JAVA_HOME=/path/to/jdk-17 mvn --version ``` ## ๐Ÿค Development ### Setting Up Development Environment 1. **Fork and clone** the repository 2. **Import** into your IDE as a Maven project 3. **Configure** JDK 17+ as project SDK 4. **Run tests** to verify setup: `mvn test` ### Code Style The project follows CodeLibs formatting standards: ```bash # Format code before committing mvn formatter:format # Check formatting mvn formatter:validate ``` ### Building Documentation ```bash # Generate API documentation mvn javadoc:javadoc # View generated docs open target/site/apidocs/index.html ``` ## ๐Ÿ“„ License Licensed under the [Apache License, Version 2.0](LICENSE). See the `LICENSE` file for details. This project includes components from: - Apache Xerces (Apache License 2.0) - XML Resolver (Apache License 2.0) ## ๐Ÿ—‚ Related Projects - [Apache Xerces2-J](http://xerces.apache.org/xerces2-j/) - Original Apache project - [XML Commons](http://xml.apache.org/commons/) - XML API commons - [Apache XML Project](http://xml.apache.org/) - XML tools and libraries