Skip to content

Commit

Permalink
WIP #7
Browse files Browse the repository at this point in the history
- test that JSON files converted via PHP can be reconverted back to XML without loss of information

other changes:
- regenerate random files
- validate random JSON files with PHP validator
  • Loading branch information
Paolo Greppi committed Jul 3, 2018
1 parent 60680f1 commit c65a84c
Show file tree
Hide file tree
Showing 42 changed files with 3,410 additions and 2,920 deletions.
15 changes: 15 additions & 0 deletions bin/convert_samples_js.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/sh
#
# converts to JSON the sample XML invoice files from fatturapa.gov.it
# using the javascript converter
#
# Copyright (c) 2018, Paolo Greppi <[email protected]>
# License: BSD 3-Clause

set -e

for name in "samples/IT01234567890_FPA01" "samples/IT01234567890_FPA02" "samples/IT01234567890_FPA03" "samples/IT01234567890_FPR01" "samples/IT01234567890_FPR02" "samples/IT01234567890_FPR03"
do
echo "converting $name.xml"
./bin/xml2json.js "$name.xml" > "$name-js.json"
done
3 changes: 2 additions & 1 deletion bin/convert_samples.sh → bin/convert_samples_php.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/bin/sh
#
# converts to JSON the sample XML invoice files from fatturapa.gov.it
# using the PHP converter
#
# Copyright (c) 2018, Paolo Greppi <[email protected]>
# License: BSD 3-Clause
Expand All @@ -10,5 +11,5 @@ set -e
for name in "samples/IT01234567890_FPA01" "samples/IT01234567890_FPA02" "samples/IT01234567890_FPA03" "samples/IT01234567890_FPR01" "samples/IT01234567890_FPR02" "samples/IT01234567890_FPR03"
do
echo "converting $name.xml"
./bin/xml2json.js "$name.xml" > "$name.json"
./bin/xml2json.php "$name.xml" > "$name-php.json"
done
6 changes: 4 additions & 2 deletions bin/generate_random.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ do
name=$(printf %02d "$i")
echo "generating $name.json"
bin/fake.js > "random/$name.json"
echo "validate $name.json"
bin/validate_json.js "random/$name.json"
echo "validate $name.json with javascript"
./bin/validate_json.js "random/$name.json"
echo "validate $name.json with PHP"
./bin/validate_json.php "random/$name.json"
echo "convert to $name.xml"
bin/hbs.js "random/$name.json" > "random/$name.xml"
# echo "validate $name.xml"
Expand Down
16 changes: 11 additions & 5 deletions bin/reconvert_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@

for name in "IT01234567890_FPA01" "IT01234567890_FPA02" "IT01234567890_FPA03" "IT01234567890_FPR01" "IT01234567890_FPR02" "IT01234567890_FPR03"
do
echo "reconverting $name"
./bin/hbs.js "samples/$name.json" > "$name.xml"
xmllint --debug --schema Schema_del_file_xml_FatturaPA_versione_1.2_cleanup.xsd "$name.xml" -noout
diff "samples/$name.xml" "$name.xml"
rm "$name.xml"
echo "reconverting $name-js"
./bin/hbs.js "samples/$name-js.json" > "$name-js.xml"
# xmllint --debug --schema Schema_del_file_xml_FatturaPA_versione_1.2_cleanup.xsd "$name-js.xml" -noout
diff "samples/$name.xml" "$name-js.xml"
rm "$name-js.xml"

echo "reconverting $name-php"
./bin/hbs.js "samples/$name-php.json" > "$name-php.xml"
# xmllint --debug --schema Schema_del_file_xml_FatturaPA_versione_1.2_cleanup.xsd "$name-js.xml" -noout
diff "samples/$name.xml" "$name-php.xml"
rm "$name-php.xml"
done
2 changes: 1 addition & 1 deletion bin/validate_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ var fs = require('fs');
var validate = require('json-schema/lib/validate').validate;

if (process.argv.length <= 2) {
console.log("Usage: json2xml file.json");
console.log("Usage: validate_json.js file.json");
process.exit(-1);
}

Expand Down
2 changes: 1 addition & 1 deletion bin/validate_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
require_once './vendor/autoload.php';

if (count($argv) <= 1) {
echo "Usage: validate.php file.json\n";
echo "Usage: validate_json.php file.json\n";
exit(-1);
}

Expand Down
14 changes: 9 additions & 5 deletions bin/validate_samples_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@

set -e

for name in "samples/IT01234567890_FPA01.json" "samples/IT01234567890_FPA02.json" "samples/IT01234567890_FPA03.json" "samples/IT01234567890_FPR01.json" "samples/IT01234567890_FPR02.json" "samples/IT01234567890_FPR03.json"
for name in "samples/IT01234567890_FPA01" "samples/IT01234567890_FPA02" "samples/IT01234567890_FPA03" "samples/IT01234567890_FPR01" "samples/IT01234567890_FPR02" "samples/IT01234567890_FPR03"
do
echo "validating $name with javascript"
./bin/validate_json.js "$name"
echo "validating $name with PHP"
./bin/validate_json.php "$name"
echo "validating $name-js.json with javascript"
./bin/validate_json.js "$name-js.json"
echo "validating $name-js.json with PHP"
./bin/validate_json.php "$name-js.json"
echo "validating $name-php.json with javascript"
./bin/validate_json.js "$name-php.json"
echo "validating $name-php.json with PHP"
./bin/validate_json.php "$name-php.json"
done
4 changes: 2 additions & 2 deletions bin/xml2json.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/nodejs
//
// converts the supplied XML file to JSON
// converts the supplied XML invoice file to JSON
//
// Copyright (c) 2018, Paolo Greppi <[email protected]>
// License: BSD 3-Clause
Expand All @@ -11,7 +11,7 @@ var parser = require('xml2json');
var fs = require('fs');

if (process.argv.length <= 2) {
console.log("Usage: xml2json file.json");
console.log("Usage: xml2json.js file.xml");
process.exit(-1);
}

Expand Down
21 changes: 21 additions & 0 deletions bin/xml2json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/php
<?php
// converts the supplied XML invoice file to JSON
//
// Copyright (c) 2018, Paolo Greppi <[email protected]>
// License: BSD 3-Clause

declare(strict_types=1);

require_once './vendor/autoload.php';
require("www/Xml2Json.php");

if (count($argv) <= 1) {
echo "Usage: xml2json.php file.xml\n";
exit(-1);
}

$filename = $argv[1];

$obj = new Simevo\Xml2Json($filename);
echo $obj->result();
Loading

0 comments on commit c65a84c

Please sign in to comment.