Splitting large xml files in subfiles without memory conflicts

I have XML like the following

<Jobs>
   <job>
   ....
   </job>
   <job>
   ....
   </job>
   ....
</Jobs>

Now, what is the best way to write each node job in a separate file without bringing the whole file to memory using xmlreader and xmlwriter or other parameters?

+5
source share
3 answers
  • Create an XmlReader for the input file.
  • Place the reader on the first element of the assignment.
  • Create an XmlReader subtree using the ReadSubtree Method .
  • Create an XmlWriter for the output file.
  • Copy the contents of the XmlReader subtree into the XmlWriter using the WriteNode method .
  • , .
    , .
+3

XSLT 3.0 , XSLT 3.0 Saxon-EE 9.4:

<xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:mode streamable="yes" on-no-match="shallow-copy">
<xsl:template match="job">
  <xsl:result-document href="job{position()}.xml">
    <xsl:next-match/>
  </xsl:result-document>
</xsl:template>
</xsl:stylesheet>
+2

, ( ), StreamReader. . , </job>. .

, , XmlReader .

0

All Articles