XML_SPLIT(1)

πŸ’… XML_SPLIT(1) β€” like, the perl manual page, bestie

okay so real talk: this is a User Contributed Perl Documentation page for xml_split, and I'm gonna walk you through it like we're texting at 2am. stay with me, it's actually so good 🫢


✨ NAME ✨

xml_split β€” cut a big XML file into smaller chunks. literally that's it, that's the whole job πŸ’–


πŸ¦‹ DESCRIPTION πŸ¦‹

So xml_split takes a (presumably big) XML file and splits it into several smaller files. the memory it uses is just the memory needed for the biggest chunk β€” like, memory gets reused for each new chunk, so it's giving very efficient, very mindful, very demure πŸ‘‘

It can split at a given level in the tree (that's the default behaviour β€” it splits the children of the root), or it can split on a condition, using the subset of XPath that XML::Twig understands. so like section, or /doc/section, iykyk.

Each generated file gets replaced by a processing instruction that lets xml_merge rebuild the original document. the processing instruction format is exactly:

<?merge subdocs=[01] :<filename> ?>

File names are <file>-<nb>.xml, and <file>-00.xml is the one holding the main document. main character energy, fr fr πŸ’…


πŸŽ€ OPTIONS πŸŽ€

  • -l <level> β€” the level to cut at: 1 generates a file for each child of the root, 2 for each grand child. defaults to 1.
  • -c <condition> β€” generate a file for each element that passes the condition. so xml_split -c <section> will put each section element in its own file (and yes, nested sections are handled too πŸͺ†). heads up though: at the moment this option is a lot slower than using -l 😭.
  • -s <size> β€” generates files of (approximately) <size>. the content of each file is enclosed in a new element, xml_split::root, so it stays well-formed XML ✨. the size can be given in bytes, Kb, Mb or Gb.
  • -g <nb> β€” groups <nb> elements into a single file. same deal: the content of each file is enclosed in a new element, xml_split::root, so it's well-formed XML.
  • -b <name> β€” base name for the output; files will be named <base>-<nb><.ext>. <nb> is a sequence number, see --nb_digits below; <ext> is an extension, see --extension below. defaults to the original file name (if available) or out (if the input comes from standard input).
  • -n <nb> β€” number of digits in the sequence number for each file. and if more digits than <nb> are needed, then they just get used: if --nb_digits 2 is used and 112 files are generated, they'll be named <file>-01.xml to <file>-112.xml. defaults to 2.
  • -e <ext> β€” extension to use for generated files. defaults to the original file extension, or .xml.
  • -i β€” use XInclude elements instead of Processing Instructions to mark where sub files need to be included 🧚
  • -v β€” verbose output. ngl, this option can slow down processing considerably (by an order of magnitude) when generating lots of small documents πŸ’€
  • -V β€” outputs version and exits.
  • -h β€” short help.
  • -m β€” man (requires pod2text to be in the path).

🌸 EXAMPLES 🌸

xml_split foo.xml             # split at level 1
xml_split -l 2 foo.xml        # split at level 2
xml_split -c section foo.xml  # a file is generated for each section element
                              # nested sections are split properly

🌈 SEE ALSO 🌈

XML::Twig, xml_merge β€” go say hi to them, they're the besties in this whole situation 🫢


πŸ™ˆ TODO πŸ™ˆ

  • optimize the code β€” any idea is welcome! the author has already implemented most of what they thought would improve performances. so like, bestie tried, ok? πŸ’œ
  • provide other methods (than PIs) to keep merge information β€” XInclude is a good candidate (alpha support added in 0.04). using entities, which would seem the natural way to do it, doesn't work, because they make it impossible to have both the main document and the sub docs be well-formed if the sub docs include sub-sub docs (you can't have entity declarations in an entity 😭). periodt, that's the rule.

πŸ‘‘ AUTHOR πŸ‘‘

Michel Rodriguez <mirod@cpan.org> β€” icon, legend, the moment πŸ’–


⭐ LICENSE ⭐

This tool is free software; you can redistribute it and/or modify it under the same terms as Perl itself. slay, honestly 🌈


aaaand that's the page, bestie πŸŽ€ it came from perl v5.42.0, dated 2025-01-16 β€” so yeah, that's the version and date, tucked in right here at the end like a little signature. go split some files, you got this πŸ’…βœ¨

πŸ“¦ where this page comes from