Abigail-sama, I am righteously admonished. Please allow me to correct myself...
(BTW, good to see you posting here again.)
I suppose I was more concentrating on code, rather than phrasing my 'question'. I was looking more for a conversation about coding style & technique so that I could learn a better way to do something. I'm sure someone of much brain such as yourself could do this in a few lines. Perhaps I should rephrase it in a more generic, theoretical way, rather than a real world example?
I'm attempting to simply split a file into smaller files based on a search criteria. I've explained the real world application. But my approach is simply one of finding the opening XML Processing Instruction which identifies the version of the XML file. One subtopic of discussion might be why I shouldn't do that, perhaps.. For now I'm splitting up a file into smaller pieces based on a regular expression. I'm asking is there is a simpler way to do this, or if my coding style is perhaps obtuse? Comments of all temperatures are welcome. (I'm wearing my asbestos weave robes today. (; )
Here some sample data:
<?xml version = "1.0"?> <!DOCTYPE AdvanceShippingNotice SYSTEM "AdvanceShippingNotice.dtd"> <AdvanceShippingNotice> <AdvanceShipping> <AdvanceShippingDetail> </AdvanceShippingDetail> </AdvanceShipping> </AdvanceShippingNotice> <?xml version = "1.0"?> <!DOCTYPE AdvanceShippingNotice SYSTEM "AdvanceShippingNotice.dtd"> <AdvanceShippingNotice> <AdvanceShipping> <AdvanceShippingDetail> </AdvanceShippingDetail> <AdvanceShippingDetail> </AdvanceShippingDetail> <AdvanceShippingDetail> </AdvanceShippingDetail> </AdvanceShipping> <GlobalDocumentFunctionCode>ASN</GlobalDocumentFunctionCode> </AdvanceShippingNotice> <?xml version = "1.0"?> <!DOCTYPE AdvanceShippingNotice SYSTEM "AdvanceShippingNotice.dtd"> <AdvanceShippingNotice> <AdvanceShipping> <AdvanceShippingDetail> </AdvanceShippingDetail> </AdvanceShipping> <fromRole/> <toRole/> <thisDocumentGenerationDateTime> <DateTimeStamp>20010619120949</DateTimeStamp> </thisDocumentGenerationDateTime> <thisDocumentIdentifier> <ProprietaryDocumentIdentifier/> </thisDocumentIdentifier> <GlobalDocumentFunctionCode>ASN</GlobalDocumentFunctionCode> </AdvanceShippingNotice>
I have left the details of the data out for the sake of brevity, and since they don't matter.
The results of this should be three new files written to the filesystem which are themselves valid XML files.
Actually, let me correct that... Known bugs:
No zero padding of numbers in filenames to support alphabetical ordering
No actual XML validation
In reply to Re: (Abigail) XML File Slicing Golf(ish)
by gregor42
in thread XML File Slicing Golf(ish)
by gregor42
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |