【发布时间】:2019-11-29 05:23:45
【问题描述】:
我正在学习 node-js,并试图解决下面提到的问题。我尝试使用 node.js 中可用的xml-splitter 和xml-stream npm 模块,但错误发生为Error: Text data outside of root node.
我有一个文件如下
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Party tonight!</body>
</note>
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Jone</to>
<from>Dove</from>
<heading>Reminder</heading>
<body>One batch, Two batch</body>
</note>
我想把文件一分为二,如图所示
文件 1:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Party tonight!</body>
</note>
文件 2:
<?xml version="1.0" encoding="ISO-8859-1"?>
<note>
<to>Jone</to>
<from>Dove</from>
<heading>Reminder</heading>
<body>One batch, Two batch</body>
</note>
【问题讨论】:
-
初始文件不是有效的 XML 文件,但包含两个连接的 XML 文件。这就是 XML NPM 模块不起作用的原因。
标签: node.js xml express split stream