我想將一個stackexchange原始數據處理成BigQuery,但首先數據使用7z壓縮格式,所以我解壓縮數據以將其移植到gz格式,但內部文件是一個XML。所以我需要將文件從xml轉換爲json。有任何想法嗎?我使用p7zip解壓縮和xml2json嘗試移植xml文件,但無法正常工作。將xml轉換爲json以將文件處理成Bigquery
<?xml version="1.0" encoding="utf-8"?> <comments> <row Id="1" PostId="1" Score="3" Text="We need to all post more questions. Last time, we kinda "rushed" to get a w hole bunch of people to sign up at the last minute (and pulled some funny stuff" CreationDate="2014-02-12T01:01:14.257" UserId="52" />..
我用xml2json xml2json -t json2xml -o xxx.xml yyy.json
其他測試使用XML-JSON **大衛recomendations
使用這個文件users.xml中(大小895M)從stackoverflow.com-Users.7z使用此命令:XML,JSON users.xml中排> Users.json
xml-json Users.xml row > Users.json /usr/local/lib/node_modules/xml-json/node_modules/xml-nodes/index.js:19 this.soFar += String(chunk)
RangeError: Invalid string length
at XmlNodes._transform (/usr/local/lib/node_modules/xml-json/node_modules/xml-nodes/index.js:19:15)
at XmlNodes.Transform._read (_stream_transform.js:183:22)
at XmlNodes.Transform._write (_stream_transform.js:167:12)
at doWrite (_stream_writable.js:265:12)
at writeOrBuffer (_stream_writable.js:252:5)
at XmlNodes.Writable.write (_stream_writable.js:197:11)
at Duplexify._write (/usr/local/lib/node_modules/xml-json/node_modules/pumpify/node_modules/duplexify/index.js:197:22)
at doWrite (/usr/local/lib/node_modules/xml-json/node_modules/pumpify/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:237:10)
at writeOrBuffer (/usr/local/lib/node_modules/xml-json/node_modules/pumpify/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:227:5)
at Writable.write (/usr/local/lib/node_modules/xml-json/node_modules/pumpify/node_modules/duplexify/node_modules/readable-stream/lib/_stream_writable.js:194:11)
at ReadStream.ondata (_stream_readable.js:539:20)
at ReadStream.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:162:16)
at ReadStream.Readable.push (_stream_readable.js:125:10)
at onread (fs.js:1581:12)
at Object.wrapper [as oncomplete] (fs.js:482:17)
轉換複雜的FpML XML文本(TSV)
的確如此,我無法處理數據。我使用了stackoverflow.com-Comments.7z(來自https://archive.org/details/stackexchange)1.8GB。但是當嘗試將xml文件轉換爲json到7z中。這個過程永無止境。我使用了13GB RAM和2個處理器的虛擬機。也許存在其他方式來處理大文件o將目標文件轉換成BigQuery數據。 – 2014-10-01 14:22:42
看。您的機器規格對於此任務並不重要。獲取可以打開大型文本文件的文本編輯器。打開XML並剪下一個有代表性的樣本。從該示例中,仔細創建您想要查看的JSON。在這裏發佈這兩個代碼示例,我(或其他人,就此而言)將能夠看到他們可以做什麼。你不會得到如下答案:*「只需使用工具XYZ將XML轉換爲JSON即可。」部分原因是你沒有發佈任何硬性要求,部分原因是這個魔法工具可能不存在。 – Tomalak 2014-10-01 14:37:00