Hi XML heads, here’s the solution for parsing CSV using pure SGML making use of SHORTREF to turn tabs and newlines into tag sequences. Could be made more elegant using tag inference, omitted element names in end-element tags („</>“) and whatnot, but this solution, up to element names and other details, has the benefit of being documented at http://sgmljs.net/docs/sgmlrefman.html#short-references : <!DOCTYPE document [ <!ELEMENT document - - (row+)> <!ELEMENT row - - (title,authors,date,isbn,publisher)> <!ELEMENT title - - (#PCDATA)> <!ELEMENT authors - - (#PCDATA)> <!ELEMENT date - - (#PCDATA)> <!ELEMENT isbn - - (#PCDATA)> <!ELEMENT publisher - - (#PCDATA)> <!ENTITY books SYSTEM "books.txt"> <!ENTITY start-fields "<row><title>"> <!ENTITY end-row "</publisher></row>"> <!ENTITY end-title "</title><authors>"> <!ENTITY end-authors "</authors><date>"> <!ENTITY end-date "</date><isbn>"> <!ENTITY end-isbn "</isbn><publisher>"> <!SHORTREF in-document "&#RS;" start-fields> <!SHORTREF in-title "&#TAB;" end-title> <!SHORTREF in-authors "&#TAB;" end-authors> <!SHORTREF in-date "&#TAB;" end-date> <!SHORTREF in-isbn "&#TAB;" end-isbn> <!SHORTREF in-publisher "&#RE;" end-row> <!USEMAP in-document document> <!USEMAP in-title title> <!USEMAP in-authors authors> <!USEMAP in-date date> <!USEMAP in-isbn isbn> <!USEMAP in-publisher publisher> ]> <document> &books </document> Where books.txt is supposed to contain tab-separated data, and the SGML file is stored in doc.sgm, say. Producing XML from this is as simple as invoking „sgmlproc doc.sgm“ Have fun, Marcus Reichardt
|