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:1generates a file for each child of the root,2for each grand child. defaults to1.-c <condition>β generate a file for each element that passes the condition. soxml_split -c <section>will put eachsectionelement 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_digitsbelow;<ext>is an extension, see--extensionbelow. defaults to the original file name (if available) orout(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 2is used and 112 files are generated, they'll be named<file>-01.xmlto<file>-112.xml. defaults to2.-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 (requirespod2textto 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
- opensuse-leap 16.0: perl-XML-Twig 3.530.0-160000.2.2 Β· Artistic-1.0 OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms