evernote-data-handling

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Evernote Data Handling

Evernote 数据处理

Overview

概述

Best practices for handling Evernote data including ENML content processing, attachment management, local database sync, and ENEX export/import.
处理Evernote数据的最佳实践,包括ENML内容处理、附件管理、本地数据库同步以及ENEX导出/导入。

Prerequisites

前置条件

  • Understanding of Evernote data model (Notes, Notebooks, Tags, Resources)
  • Database for local storage (SQLite, PostgreSQL, etc.)
  • File storage for attachments
  • 了解Evernote数据模型(Notes、Notebooks、Tags、Resources)
  • 用于本地存储的数据库(SQLite、PostgreSQL等)
  • 用于存储附件的文件存储系统

Instructions

操作步骤

Step 1: Data Schema Design

步骤1:数据架构设计

Design a local database schema that mirrors Evernote's data model. Key tables:
notes
(guid, title, content, notebookGuid, created, updated, USN),
notebooks
(guid, name, stack),
tags
(guid, name),
resources
(guid, noteGuid, mime, hash, size). Track Update Sequence Numbers (USN) for incremental sync.
sql
CREATE TABLE notes (
  guid TEXT PRIMARY KEY,
  title TEXT NOT NULL,
  content TEXT,
  notebook_guid TEXT REFERENCES notebooks(guid),
  created BIGINT,
  updated BIGINT,
  usn INTEGER DEFAULT 0
);
设计一个镜像Evernote数据模型的本地数据库架构。核心表包括:
notes
(guid、title、content、notebookGuid、created、updated、USN)、
notebooks
(guid、name、stack)、
tags
(guid、name)、
resources
(guid、noteGuid、mime、hash、size)。跟踪更新序列号(USN)以实现增量同步。
sql
CREATE TABLE notes (
  guid TEXT PRIMARY KEY,
  title TEXT NOT NULL,
  content TEXT,
  notebook_guid TEXT REFERENCES notebooks(guid),
  created BIGINT,
  updated BIGINT,
  usn INTEGER DEFAULT 0
);

Step 2: ENML Content Processing

步骤2:ENML内容处理

Parse ENML to extract plain text (strip tags), convert to HTML (replace
<en-note>
with
<body>
, resolve
<en-media>
to
<img>
/
<a>
tags), or convert to Markdown. Validate ENML before sending to the API by checking for required declarations and forbidden elements.
javascript
function enmlToPlainText(enml) {
  return enml
    .replace(/<\?xml[^>]*\?>/g, '')
    .replace(/<!DOCTYPE[^>]*>/g, '')
    .replace(/<[^>]+>/g, ' ')
    .replace(/\s+/g, ' ')
    .trim();
}
解析ENML以提取纯文本(移除标签)、转换为HTML(将
<en-note>
替换为
<body>
,将
<en-media>
解析为
<img>
/
<a>
标签),或转换为Markdown。在发送至API前验证ENML,检查是否包含必需声明和禁用元素。
javascript
function enmlToPlainText(enml) {
  return enml
    .replace(/<\?xml[^>]*\?>/g, '')
    .replace(/<!DOCTYPE[^>]*>/g, '')
    .replace(/<[^>]+>/g, ' ')
    .replace(/\s+/g, ' ')
    .trim();
}

Step 3: Resource (Attachment) Handling

步骤3:资源(附件)处理

Download resources via
noteStore.getResource(guid, withData, ...)
. Store binary data locally with the MD5 hash as filename. Track MIME types for proper content-type serving. Compute hashes for integrity verification.
通过
noteStore.getResource(guid, withData, ...)
下载资源。将二进制数据以MD5哈希值作为文件名存储在本地。跟踪MIME类型以正确提供内容类型。计算哈希值以验证数据完整性。

Step 4: Sync Data Manager

步骤4:同步数据管理器

Implement incremental sync using
getSyncState()
to get the current server USN, then
getSyncChunk()
to fetch changes since your last sync. Process chunks in order: notebooks first, then tags, then notes, then resources.
javascript
const syncState = await noteStore.getSyncState();
if (syncState.updateCount > lastSyncUSN) {
  const chunk = await noteStore.getSyncChunk(lastSyncUSN, 100, true);
  // Process chunk.notebooks, chunk.tags, chunk.notes, chunk.resources
}
使用
getSyncState()
获取当前服务器USN,然后通过
getSyncChunk()
获取自上次同步以来的变更。按顺序处理数据块:先处理笔记本,再处理标签,接着是笔记,最后是资源。
javascript
const syncState = await noteStore.getSyncState();
if (syncState.updateCount > lastSyncUSN) {
  const chunk = await noteStore.getSyncChunk(lastSyncUSN, 100, true);
  // Process chunk.notebooks, chunk.tags, chunk.notes, chunk.resources
}

Step 5: Data Export

步骤5:数据导出

Export notes to ENEX (Evernote's XML export format), JSON, or Markdown. ENEX preserves the full note structure including resources and is compatible with Evernote import.
For the complete data schema, sync manager, ENML processor, and export implementations, see Implementation Guide.
将笔记导出为ENEX(Evernote的XML导出格式)、JSON或Markdown。ENEX保留完整的笔记结构(包括资源),且与Evernote导入功能兼容。
如需完整的数据架构、同步管理器、ENML处理器和导出实现,请查看实现指南

Output

输出结果

  • SQL schema for local Evernote data storage
  • ENML-to-text and ENML-to-HTML converters
  • Resource download and local storage manager
  • Incremental sync engine using USN tracking
  • ENEX, JSON, and Markdown export utilities
  • 用于本地Evernote数据存储的SQL架构
  • ENML转文本和ENML转HTML转换器
  • 资源下载与本地存储管理器
  • 基于USN跟踪的增量同步引擎
  • ENEX、JSON和Markdown导出工具

Error Handling

错误处理

ErrorCauseSolution
BAD_DATA_FORMAT
Malformed ENML during updateValidate ENML with DTD check before API call
QUOTA_REACHED
Upload limit exceededCheck
user.accounting.uploaded
before creating notes
DATA_CONFLICT
Note modified since last readRefetch note by GUID and merge changes
Sync chunk gapsMissed USN rangeRequest full sync from USN 0
错误类型原因解决方案
BAD_DATA_FORMAT
更新时ENML格式错误在调用API前通过DTD检查验证ENML
QUOTA_REACHED
超出上传限制创建笔记前检查
user.accounting.uploaded
DATA_CONFLICT
笔记自上次读取后已被修改通过GUID重新获取笔记并合并变更
同步数据块缺失遗漏USN范围从USN 0开始请求全量同步

Resources

参考资源

Next Steps

下一步

For enterprise features, see
evernote-enterprise-rbac
.
如需企业级功能,请查看
evernote-enterprise-rbac

Examples

示例

Local mirror: Sync all notes to a local SQLite database using incremental sync. Store resources on disk keyed by MD5 hash. Use the local mirror for full-text search without API calls.
Markdown export: Convert all notes in a notebook to Markdown files, preserving folder structure from notebook stacks, and saving attachments to an
assets/
directory.
本地镜像:使用增量同步将所有笔记同步到本地SQLite数据库。将资源以MD5哈希值为键存储在磁盘上。使用本地镜像实现无需API调用的全文搜索。
Markdown导出:将笔记本中的所有笔记转换为Markdown文件,保留笔记本栈的文件夹结构,并将附件保存到
assets/
目录。