• # Essai en ligne.

    Posté par (site web personnel) . En réponse au journal Code natif et Node.js - parser et préprocesseur XML. Évalué à 1.

    Pour ceux qui ne connaissent pas (c'était mon cas il n'y pas encore bien longtemps), il est possible d'essayer le paquet en ligne, grâce à RunKit.

    À titre d'exemple, copiez le code ci-dessous dans le champ de saisi, puis cliquez sur le bouton vert (run) situé en-bas à droite de ce même champ :

    var xppq = require("xppq");
    var str = require("string-to-stream");
    var xml = '<?xml version="1.0" encoding="UTF-8"?> <SomeTag xmlns:xpp="http://q37.info/ns/xpp/" AnAttribute="SomeAttributeValue"> <SomeOtherTag AnotherAttribute="AnotherAttributeValue">TagValue</SomeOtherTag> <xpp:define name="SomeMacro"> <xpp:bloc>Some macro content !</xpp:bloc> </xpp:define> <YetAnotherTag YetAnotherAttribute="YetAnotherAttributeValue"> <xpp:expand select="SomeMacro"/> </YetAnotherTag> </SomeTag>';
    function write(text) {
     console.log(text);
    }
    write( xppq.componentInfo() );
    write( xppq.wrapperInfo() );
    function callback(token, tag, attribute, value) {
     switch (token) {
     case xppq.tokens.ERROR:
     write(">>> ERROR: '" + value + "'\n");
     break;
     case xppq.tokens.START_TAG:
     write("Start tag: '" + tag + "'\n");
     break;
     case xppq.tokens.ATTRIBUTE:
     write("Attribute: '" + attribute + "' = '" + value + "'\n");
     break;
     case xppq.tokens.VALUE:
     write("Value: '" + value.trim() + "'\n");
     break;
     case xppq.tokens.END_TAG:
     write("End tag: '" + tag + "'\n");
     break;
     default:
     throw ("Unknown token !!!");
     break;
     }
    }
    xppq.parse(new xppq.Stream( str(xml)).on('error', (err) => console.error('>>> ERROR : ' + err)), callback);

    (Pour ceux qui connaissent RunKit, pourquoi process.stdout.write(...) ne fonctionne-t-il pas, et y a-t-il moyen d'avoir quelques chose d'équivalent, mis à part console ?)

    Zelbinium: pour la génération qui crée, pas celle qui scrolle...