Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ XSD=https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd
# XSD validation — pick any stack (schema + xml, schema-first):
python XSD_Validation/python/validate.py "$XSD" $SRC
dotnet run --project XSD_Validation/dotnet -- "$XSD" $SRC
./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$XSD $SRC"
java XSD_Validation/java/XsdValidate.java "$XSD" $SRC # JDK 11+ only, no Maven needed
XSD_Validation/cli/validate.sh "$XSD" $SRC # Windows: pwsh .../validate.ps1

# Schematron business rules (SVRL; exit 0 = no ERROR-role failures)
Expand Down
12 changes: 11 additions & 1 deletion XSD_Validation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,17 @@ python XSD_Validation/python/validate.py "$REL" FundsXML_Files/4.2.9/positions/M
python XSD_Validation/python/validate.py "$REL" tests/fixtures/invalid/xsd-invalid_Positions.xml # exit 1
```

Java (standalone): `./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$REL <file>"`
Java (standalone, JDK 11+ only — no Maven needed, the example has no
dependencies beyond the JDK):

```bash
java XSD_Validation/java/XsdValidate.java "$REL" FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml # exit 0
java XSD_Validation/java/XsdValidate.java "$REL" tests/fixtures/invalid/xsd-invalid_Positions.xml # exit 1
```

(Windows: `java XSD_Validation\java\XsdValidate.java <schema> <xml-file>`.)
The same class also runs through the Maven aggregator, which is what CI uses:
`./mvnw -q -pl XSD_Validation/java compile exec:java -Dexec.args="$REL <file>"`
(`mvnw.cmd` on Windows).

.NET (standalone): `dotnet run --project XSD_Validation/dotnet -- "$REL" <file>`
Expand Down
30 changes: 26 additions & 4 deletions XSD_Validation/java/XsdValidate.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
// XSD validation in native Java (no JAXB) via javax.xml.validation.
//
// Standalone & cross-platform — no prior tool, no bash, works on Windows.
// Run from the repo root with the committed Maven Wrapper:
// The only dependency is the JDK itself (javax.xml.validation + java.net.http),
// so no build tool is needed: JDK 11+ compiles and runs a single source file
// directly (JEP 330). Run from the repo root:
// java XSD_Validation/java/XsdValidate.java \
// https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd \
// FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml
// (Windows: java XSD_Validation\java\XsdValidate.java <schema> <xml-file>)
//
// Alternatively via the committed Maven Wrapper (the module is part of the
// root aggregator so `./mvnw compile` builds it together with the other
// examples; it has no dependencies of its own):
// ./mvnw -q -pl XSD_Validation/java compile exec:java \
// -Dexec.args="https://github.com/fundsxml/schema/releases/download/4.2.9/FundsXML.xsd \
// FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml"
// -Dexec.args="<schema> <xml-file>"
// Exit: 0 = valid, 1 = invalid, 2 = usage/setup error
//
// You give it exactly two things: the schema and the instance. <schema> is a
Expand Down Expand Up @@ -79,13 +88,26 @@ public static void main(String[] args) throws Exception {
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file");
factory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");

Schema fundsXmlSchema = factory.newSchema(schemaFile);
// A missing, unreadable or malformed *schema* is a setup error
// (exit 2), not an invalid instance (exit 1) — report it in one
// line instead of letting the SAXParseException stack-trace out.
Schema fundsXmlSchema;
try {
fundsXmlSchema = factory.newSchema(schemaFile);
} catch (SAXParseException e) {
System.err.println("cannot load schema " + schemaArg + ": "
+ e.getMessage());
System.exit(2);
return;
}
Validator validator = fundsXmlSchema.newValidator();
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");
validator.setProperty(XMLConstants.ACCESS_EXTERNAL_SCHEMA, "file");

final boolean[] failed = {false};
validator.setErrorHandler(new ErrorHandler() {
// Schema warnings (e.g. unused imports) never affect
// validity — deliberately ignored to keep the output clean.
public void warning(SAXParseException e) { }
public void error(SAXParseException e) { report(e); }
public void fatalError(SAXParseException e) { report(e); }
Expand Down
13 changes: 9 additions & 4 deletions XSD_Validation/java/pom.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
XSD validation in native Java (javax.xml.validation, no JAXB). No third-party
dependencies — the JDK is the whole runtime. The schema is obtained by the
example itself (env var / local cache / official download), see XsdValidate.java.
dependencies at all: the JDK is the whole runtime. Because of that, Maven is
NOT required to run this example. The JDK's source launcher (JDK 11+) does it
in one call from the repo root:
java XSD_Validation/java/XsdValidate.java <schema> <xml-file>
where <schema> is a local FundsXML.xsd path or a remote URL, see
XsdValidate.java.

Run from the repo root:
This module exists only so the root aggregator (./mvnw compile, CI) builds
every Java example uniformly. The equivalent Maven invocation is:
./mvnw -q -pl XSD_Validation/java compile exec:java \
-Dexec.args="4.2.9 FundsXML_Files/4.2.9/positions/Mixed-Fund_Positions.xml"
-Dexec.args="<schema> <xml-file>"
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand Down