GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - openscd/xmlvalidate.js: Validate XML Schema in the browser using libxml2

BranchesTags
Open more actions menu

Latest commit

 

History

24 Commits
24 Commits

Folders and files

NameName
Last commit message
Last commit date
dist
dist
 
 
libxml2 @ b46016b
libxml2 @ b46016b
 
 
.gitmodules
.gitmodules
 
 
LICENSE
LICENSE
 
 
Makefile.am.patch
Makefile.am.patch
 
 
README.md
README.md
 
 
emmake.sh
emmake.sh
 
 
post.js
post.js
 
 
pre.js
pre.js
 
 
xmlvalidate.c
xmlvalidate.c
 
 

Repository files navigation

xmlvalidate.js

FOSSA Status

Validates XML documents against a W3C XML Schema (XSD) from the comfort of your browser.

Dependency

Emscripten

Building

On POSIX

git submodule update --init --recursive
./emmake.sh

On other OSs

This is what emmake.sh does for you on POSIX:

  1. copy xmlvalidate.c into the ./libxml2 directory

  2. change working directory to ./libxml2

  3. patch Makefile.am to include xmlvalidate.c in its libxml2_la_SOURCES

  4. emconfigure ./autogen.sh --with-minimum --with-schemas --disable-shared

    If your system does not provide a Bourne shell, consider using autoreconf --install in place of ./autogen.sh and crossing your fingers.

  5. emmake make

  6. compile the new object file xmlvalidate.o to xmlvalidate.js:

    OBJECTS="SAX.o entities.o encoding.o error.o parserInternals.o  \
        parser.o tree.o hash.o list.o xmlIO.o xmlmemory.o uri.o  \
        valid.o xlink.o HTMLparser.o HTMLtree.o debugXML.o xpath.o  \
        xpointer.o xinclude.o nanohttp.o nanoftp.o \
        catalog.o globals.o threads.o c14n.o xmlstring.o buf.o \
        xmlregexp.o xmlschemas.o xmlschemastypes.o xmlunicode.o \
        xmlreader.o relaxng.o dict.o SAX2.o \
        xmlwriter.o legacy.o chvalid.o pattern.o xmlsave.o \
        xmlmodule.o schematron.o xzlib.o"
    
    emcc -Os xmlvalidate.o $OBJECTS -o xmlvalidate.js \
    -s ALLOW_MEMORY_GROWTH=1 \
    -s EXPORTED_FUNCTIONS='["_validate", "_init"]' \
    -s EXPORTED_RUNTIME_METHODS='["cwrap"]' \
    -s 'ENVIRONMENT=worker' \
    --pre-js ../pre.js --post-js ../post.js
  7. move the resulting xmlvalidate.wasm and xlvalidate.js to ../dist/

  8. change working directory to ..

Replicate these steps manually in order to compile xmlvalidate.js on a non-POSIX-compliant operating system.

Usage

Instantiate a WebWorker for validating against your schemas like so:

if (window.Worker) {
  const worker = new Worker('worker.js');
  worker.postMessage({ content: xsd_content, name: "filename.xsd" });
  // a filename ending in ".xsd" tells the worker to load the schema
  worker.onmessage = e => {
    if (e.data.file === "filename.xsd" && e.data.loaded) {
      // our schema has been parsed and loaded
      worker.postMessage({ content: xml_content, name: "filename.xml" });
      // a filename not ending in ".xsd" tells the worker to validate
    } else if (e.data.file === "filename.xml") { // respond to errors
      console.log(e.data);
    }
  };
}

License

Apache 2.0

© 2020 OMICRON electronics GmbH

FOSSA Status

About

Validate XML Schema in the browser using libxml2

Topics

browserjavascriptlibrarylibxml2schemaschemasvalidationwasmwebwebassemblywebworkerxml

Resources

Readme
Apache-2.0 license
Activity
Custom properties

Stars

5 stars

Watchers

1 watching

Forks

7 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.