There is a very large XML file with the following content:
... <!-- XML не связаный с категориями --> ... <category id="1cat"> ... <parent>blablabla</parent> ... </category> <category id="2cat"> ... <parent>main-cat</parent> ... </category> <category id="3cat"> ... <parent>main-cat</parent> ... </category> ... <!-- другой XML не связаный с категориями --> ...
to add more than one level of hierarchy, you need to change the parent tags that contain main-cat:
<parent>main-cat</parent>
at <parent>z</parent>
where z is the first character from the id of the parent <category ... >
result:
<category id="1cat"> ... <parent>blablabla</parent> ... </category> <category id="2cat"> ... <parent>2</parent> ... </category> <category id="3cat"> ... <parent>3</parent> ... </category>
I want to use an existing npm-module. There are lots of modules xml2js, xml2json, xml-split, xml-stream, xml-streaming, sax .... it is not clear how and how best to use.
I would like to do everything in the stream, with low memory costs and quickly. The best solution is to split the xml into top-level nodes for parsing them separately, but I did not find such a plugin.