{"id":37943952,"url":"https://github.com/jacoelho/xsd","last_synced_at":"2026-04-25T23:10:37.275Z","repository":{"id":331674252,"uuid":"1129302976","full_name":"jacoelho/xsd","owner":"jacoelho","description":"Pure Go XSD 1.0 validator","archived":false,"fork":false,"pushed_at":"2026-04-13T10:45:01.000Z","size":4465,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-13T11:30:59.579Z","etag":null,"topics":["go","xsd","xsd-validation"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jacoelho.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-01-06T22:42:12.000Z","updated_at":"2026-04-13T10:45:08.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/jacoelho/xsd","commit_stats":null,"previous_names":["jacoelho/xsd"],"tags_count":37,"template":false,"template_full_name":null,"purl":"pkg:github/jacoelho/xsd","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacoelho%2Fxsd","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacoelho%2Fxsd/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacoelho%2Fxsd/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacoelho%2Fxsd/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jacoelho","download_url":"https://codeload.github.com/jacoelho/xsd/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jacoelho%2Fxsd/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32279701,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-25T18:29:39.964Z","status":"ssl_error","status_checked_at":"2026-04-25T18:29:32.149Z","response_time":59,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["go","xsd","xsd-validation"],"created_at":"2026-01-16T17:47:50.987Z","updated_at":"2026-04-25T23:10:37.266Z","avatar_url":"https://github.com/jacoelho.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# XSD 1.0 Validator for Go\n\nXSD 1.0 validation for Go with `io/fs` schema loading and streaming XML validation.\n\n## Install\n\n```bash\ngo get github.com/jacoelho/xsd\n```\n\n## Quickstart\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"strings\"\n\t\"testing/fstest\"\n\n\t\"github.com/jacoelho/xsd\"\n)\n\nfunc main() {\n\tschemaXML := `\u003c?xml version=\"1.0\"?\u003e\n\u003cxs:schema xmlns:xs=\"http://www.w3.org/2001/XMLSchema\"\n           targetNamespace=\"http://example.com/simple\"\n           elementFormDefault=\"qualified\"\u003e\n  \u003cxs:element name=\"person\"\u003e\n    \u003cxs:complexType\u003e\n      \u003cxs:sequence\u003e\n        \u003cxs:element name=\"name\" type=\"xs:string\"/\u003e\n        \u003cxs:element name=\"age\" type=\"xs:integer\"/\u003e\n      \u003c/xs:sequence\u003e\n    \u003c/xs:complexType\u003e\n  \u003c/xs:element\u003e\n\u003c/xs:schema\u003e`\n\n\tfsys := fstest.MapFS{\n\t\t\"simple.xsd\": \u0026fstest.MapFile{Data: []byte(schemaXML)},\n\t}\n\n\tschema, err := xsd.CompileFS(fsys, \"simple.xsd\", xsd.CompileConfig{})\n\tif err != nil {\n\t\tfmt.Printf(\"Compile schema: %v\\n\", err)\n\t\treturn\n\t}\n\n\txmlDoc := `\u003c?xml version=\"1.0\"?\u003e\n\u003cperson xmlns=\"http://example.com/simple\"\u003e\n  \u003cname\u003eJohn Doe\u003c/name\u003e\n  \u003cage\u003e30\u003c/age\u003e\n\u003c/person\u003e`\n\n\tif err := schema.Validate(strings.NewReader(xmlDoc)); err != nil {\n\t\tif violations, ok := xsd.AsValidations(err); ok {\n\t\t\tfor _, v := range violations {\n\t\t\t\tfmt.Println(v.Error())\n\t\t\t}\n\t\t\treturn\n\t\t}\n\t\tfmt.Printf(\"Validate: %v\\n\", err)\n\t\treturn\n\t}\n\n\tfmt.Println(\"Document is valid\")\n}\n```\n\n## Compile API\n\nSingle-root compile:\n\n```go\nschema, err := xsd.CompileFS(fsys, \"schema.xsd\", xsd.CompileConfig{})\n```\n\nFile-based compile:\n\n```go\nschema, err := xsd.CompileFile(\"schema.xsd\", xsd.CompileConfig{})\n```\n\nMulti-root compile:\n\n```go\ncompiler := xsd.NewCompiler(xsd.CompileConfig{\n\tSource: xsd.SourceConfig{AllowMissingImportLocations: true},\n})\nschema, err := compiler.CompileSources([]xsd.Source{\n\t{FS: fsysA, Path: \"schema-a.xsd\"},\n\t{FS: fsysB, Path: \"schema-b.xsd\"},\n})\nif err != nil {\n\t// handle\n}\n```\n\n## Validation\n\nDefault validation:\n\n```go\nif err := schema.Validate(strings.NewReader(xmlDoc)); err != nil {\n\t// handle\n}\n```\n\nExplicit validator configuration:\n\n```go\nvalidator, err := schema.NewValidator(\n\txsd.ValidateConfig{XML: xsd.XMLConfig{\n\t\tMaxDepth:     512,\n\t\tMaxTokenSize: 1 \u003c\u003c 20,\n\t}},\n)\nif err != nil {\n\t// handle\n}\n\nif err := validator.Validate(strings.NewReader(xmlDoc)); err != nil {\n\t// handle\n}\n```\n\nValidate files:\n\n```go\nif err := schema.ValidateFile(\"document.xml\"); err != nil {\n\t// handle\n}\nif err := validator.ValidateFSFile(fsys, \"document.xml\"); err != nil {\n\t// handle\n}\n```\n\n## Config\n\nZero-value config uses defaults. Set only limits or policies that need to differ.\n\n```go\nschema, err := xsd.CompileFS(fsys, \"schema.xsd\", xsd.CompileConfig{\n\tSource: xsd.SourceConfig{\n\t\tAllowMissingImportLocations: true,\n\t\tXML: xsd.XMLConfig{\n\t\t\tMaxDepth: 512,\n\t\t},\n\t},\n\tBuild: xsd.BuildConfig{\n\t\tMaxDFAStates: 4096,\n\t},\n\tValidate: xsd.ValidateConfig{\n\t\tXML: xsd.XMLConfig{\n\t\t\tMaxAttrs:     256,\n\t\t\tMaxTokenSize: 1 \u003c\u003c 20,\n\t\t},\n\t},\n})\n```\n\n## Loading behavior\n\n- `CompileFS` and `Compiler.CompileSources` accept any `fs.FS`; include/import locations resolve relative to the including schema path.\n- `CompileFile` loads the explicit entry path as requested and confines nested include/import resolution to that path's containing directory tree.\n- Includes must resolve successfully.\n- Imports without `schemaLocation` are rejected unless `SourceConfig.AllowMissingImportLocations` is set.\n\n## Validation behavior\n\n- `Schema.Validate` is safe for concurrent use.\n- Validation is streaming; the document is not loaded into a DOM.\n- Instance-document schema hints (`xsi:schemaLocation`, `xsi:noNamespaceSchemaLocation`) are ignored.\n\n## Error handling\n\n`Schema.Validate` returns `xsd.ValidationList` for validation failures and XML parsing failures.\nValidation calls made without a loaded schema return a caller-classified `xsd.Error`.\n`Schema.ValidateFile` can return file I/O errors before validation starts.\n\nEach `xsd.Validation` includes:\n\n- `Code`\n- `Message`\n- `Path`\n- `Line` and `Column` when available\n- `Expected` and `Actual` when available\n\n## Constraints and limits\n\n- XSD 1.0 only.\n- No HTTP imports.\n- Regex patterns must be compatible with Go's `regexp`.\n- `xs:redefine` is not supported.\n- DateTime parsing uses `time.Parse` (years 0001-9999; no year 0, BCE, or \u003e9999).\n- DTDs and external entity resolution are not supported.\n- Instance documents must be UTF-8.\n\n## CLI (`xmllint`)\n\n```bash\nmake xmllint\n./bin/xmllint --schema schema.xsd document.xml\n```\n\nOptions:\n\n- `--schema` (required): path to the XSD schema file\n- `--cpuprofile`: write a CPU profile to a file\n- `--memprofile`: write a heap profile to a file\n\n## Testing\n\n```bash\ngo test -timeout 60s ./...\nmake w3c\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoelho%2Fxsd","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjacoelho%2Fxsd","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjacoelho%2Fxsd/lists"}