Git Product home page Git Product logo

xmlvalidate.js's Introduction

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

xmlvalidate.js's People

Contributors

ca-d avatar fossabot avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.