The Daily WTF
XML is, arguably, an overspecified language. Every aspect of XML has a standard to interact with it or transform it or manipulate it, and that standard is also defined in XML. Each specification related to XML fits together into a soup that does all the things and solves every problem you could possibly have.
Though Owe had a problem that didn’t quite map to the XML specification(s). Specifically, he needed to parse absolutely broken XML files.
bool Sorter::Work() { if(this->__disposed) throw gcnew ObjectDisposedException(“Object has been disposed”); if(this->_splitFiles) { List<Document^>^ docs = gcnew List<Document^>(); for each(FileInfo ^file in this->_sourceDir->GetFiles(“*.xml”)) { XElement ^xml = XElement::Load(file->FullName); xml->Save(file->FullName); long count = 0; for each(XElement^ rec in xml->Elements(“REC”)) { if(rec->Attribute(“NAME”)->Value == this->_mainLevel) count++; } if(count < 2) continue; StreamReader ^reader = gcnew StreamReader(file->OpenRead()); StringBuilder ^sb = gcnew StringBuilder(“<FILE NAME=”blah”>”); bool first = true; bool added = false; Regex ^isRecOrFld = gcnew Regex(“^s+<[REC|FLD].*$”); Regex ^isEndOfRecOrFld =
To read the full article click on the 'post' link at the top.