mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Read and parse XMl
This commit is contained in:
parent
cd64ba9b61
commit
bd4f979375
@ -1,17 +1,152 @@
|
||||
require('app-module-path').addPath(__dirname);
|
||||
|
||||
import { WebApi } from 'src/web-api.js'
|
||||
const Promise = require('promise');
|
||||
const fs = require('fs');
|
||||
const xml2js = require("xml2js");
|
||||
|
||||
// setTimeout(() => {
|
||||
// console.info('ici');
|
||||
// }, 1000);
|
||||
function parseXml(xml) {
|
||||
return new Promise((resolve, reject) => {
|
||||
xml2js.parseString(xml, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function readFile(path, options = null) {
|
||||
return new Promise((resolve, reject) => {
|
||||
fs.readFile(path, options, (err, result) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
readFile('/home/laurent/Downloads/sample-enex.xml', 'utf8').then((content) => {
|
||||
return parseXml(content);
|
||||
}).then((doc) => {
|
||||
let notes = doc['en-export']['note'];
|
||||
for (let i = 0; i < notes.length; i++) {
|
||||
let note = notes[i];
|
||||
console.info(note);
|
||||
}
|
||||
}).catch((error) => {
|
||||
console.error('Error reading XML file', error);
|
||||
});
|
||||
|
||||
|
||||
let api = new WebApi('http://joplin.local');
|
||||
|
||||
api.post('sessions', null, {
|
||||
email: 'laurent@cozic.net',
|
||||
password: '12345678',
|
||||
}).then((session) => {
|
||||
console.info(session);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// import { WebApi } from 'src/web-api.js'
|
||||
|
||||
// let api = new WebApi('http://joplin.local');
|
||||
|
||||
// api.post('sessions', null, {
|
||||
// email: 'laurent@cozic.net',
|
||||
// password: '12345678',
|
||||
// }).then((session) => {
|
||||
// console.info(session);
|
||||
// });
|
||||
|
||||
|
||||
// <?xml version="1.0" encoding="UTF-8"?>
|
||||
// <!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export3.dtd">
|
||||
// <en-export export-date="20130730T205637Z" application="Evernote" version="Evernote Mac">
|
||||
// <note>
|
||||
// <title>Test Note for Export</title>
|
||||
// <content>
|
||||
// <![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
// <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
|
||||
// <en-note style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
|
||||
// Hello, World.
|
||||
// <div>
|
||||
// <br/>
|
||||
// </div>
|
||||
// <div>
|
||||
// <en-media alt="" type="image/jpeg" hash="dd7b6d285d09ec054e8cd6a3814ce093"/>
|
||||
// </div>
|
||||
// <div>
|
||||
// <br/>
|
||||
// </div>
|
||||
// </en-note>
|
||||
// ]]>
|
||||
// </content>
|
||||
// <created>20130730T205204Z</created>
|
||||
// <updated>20130730T205624Z</updated>
|
||||
// <tag>fake-tag</tag>
|
||||
// <note-attributes>
|
||||
// <latitude>33.88394692352314</latitude>
|
||||
// <longitude>-117.9191355110099</longitude>
|
||||
// <altitude>96</altitude>
|
||||
// <author>Brett Kelly</author>
|
||||
// </note-attributes>
|
||||
// <resource>
|
||||
// <data encoding="base64">/9j/4AAQSkZJRgABAQAAAQABAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdCIFhZ
|
||||
// WiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLUhQ
|
||||
// <!-- ... -->
|
||||
// kfeIGT/+uufk8DpM0gyVjGfmzkgetesnUoTHJ+5Cxn86zmv4/wB75EW+QHAPUH/P9Ky+s1rtrr/wfvOm
|
||||
// dBSamnq/xPKp/hpLKmS7x4OBjgn6elee6v4OuLJirRSHb/FtyG9s9u1fR0+oTiIRvGq7W4bpisfUGk1C
|
||||
// GVWtkIyM57n1rfDY+uqigtU76ffZkUsA6iajHZ6v/P8A4B//2Q==</data>
|
||||
// <mime>image/jpeg</mime>
|
||||
// <width>1280</width>
|
||||
// <height>720</height>
|
||||
// <resource-attributes>
|
||||
// <file-name>snapshot-DAE9FC15-88E3-46CF-B744-DA9B1B56EB57.jpg</file-name>
|
||||
// </resource-attributes>
|
||||
// </resource>
|
||||
// </note>
|
||||
// <note>
|
||||
// <title>Test Note for Export</title>
|
||||
// <content>
|
||||
// <![CDATA[<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
// <!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">
|
||||
// <en-note style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">
|
||||
// Hello, World.
|
||||
// <div>
|
||||
// <br/>
|
||||
// </div>
|
||||
// <div>
|
||||
// <en-media alt="" type="image/jpeg" hash="dd7b6d285d09ec054e8cd6a3814ce093"/>
|
||||
// </div>
|
||||
// <div>
|
||||
// <br/>
|
||||
// </div>
|
||||
// </en-note>
|
||||
// ]]>
|
||||
// </content>
|
||||
// <created>20130730T205204Z</created>
|
||||
// <updated>20130730T205624Z</updated>
|
||||
// <tag>fake-tag</tag>
|
||||
// <note-attributes>
|
||||
// <latitude>33.88394692352314</latitude>
|
||||
// <longitude>-117.9191355110099</longitude>
|
||||
// <altitude>96</altitude>
|
||||
// <author>Brett Kelly</author>
|
||||
// </note-attributes>
|
||||
// <resource>
|
||||
// <data encoding="base64">/9j/4AAQSkZJRgABAQAAAQABAAD/4gxYSUNDX1BST0ZJTEUAAQEAAAxITGlubwIQAABtbnRyUkdCIFhZ
|
||||
// WiAHzgACAAkABgAxAABhY3NwTVNGVAAAAABJRUMgc1JHQgAAAAAAAAAAAAAAAAAA9tYAAQAAAADTLUhQ
|
||||
// <!-- ... -->
|
||||
// kfeIGT/+uufk8DpM0gyVjGfmzkgetesnUoTHJ+5Cxn86zmv4/wB75EW+QHAPUH/P9Ky+s1rtrr/wfvOm
|
||||
// dBSamnq/xPKp/hpLKmS7x4OBjgn6elee6v4OuLJirRSHb/FtyG9s9u1fR0+oTiIRvGq7W4bpisfUGk1C
|
||||
// GVWtkIyM57n1rfDY+uqigtU76ffZkUsA6iajHZ6v/P8A4B//2Q==</data>
|
||||
// <mime>image/jpeg</mime>
|
||||
// <width>1280</width>
|
||||
// <height>720</height>
|
||||
// <resource-attributes>
|
||||
// <file-name>snapshot-DAE9FC15-88E3-46CF-B744-DA9B1B56EB57.jpg</file-name>
|
||||
// </resource-attributes>
|
||||
// </resource>
|
||||
// </note>
|
||||
// </en-export>
|
||||
|
||||
|
@ -1,24 +1,25 @@
|
||||
{
|
||||
"name": "CliClient",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"app-module-path": "^2.2.0",
|
||||
"form-data": "^2.1.4",
|
||||
"node-fetch": "^1.7.1",
|
||||
"react": "16.0.0-alpha.6",
|
||||
"uuid": "^3.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-changed": "^7.0.0",
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-preset-env": "^1.5.1",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"query-string": "4.3.4",
|
||||
"react-native-sqlite-storage": "3.3.*"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel-changed app -d build",
|
||||
"clean": "babel-changed --reset"
|
||||
}
|
||||
"name": "CliClient",
|
||||
"version": "0.0.1",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"app-module-path": "^2.2.0",
|
||||
"form-data": "^2.1.4",
|
||||
"node-fetch": "^1.7.1",
|
||||
"promise": "^7.1.1",
|
||||
"react": "16.0.0-alpha.6",
|
||||
"uuid": "^3.0.1",
|
||||
"xml2js": "^0.4.17"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-changed": "^7.0.0",
|
||||
"babel-cli": "^6.24.1",
|
||||
"babel-preset-env": "^1.5.1",
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"query-string": "4.3.4"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "babel-changed app -d build",
|
||||
"clean": "babel-changed --reset"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user