16
1
Background
You are working as a programmer for a car sales company. Your task for this week is to program an XML parser that takes in data about available models from different car manufacturers, and pretty-prints information about the newest models. Luckily for you, the testing department has provided only one test case! The faster you can write code that passes it, the more time you have for procrastination during the rest of the week.
Input
Your input is exactly this piece of XML data, supplied by the testing department. It contains data about some car manufacturers, their series of cars, and the models in these series. You may assume a trailing newline.
<?xml version="1.0" ?>
<products>
<manufacturer name="Test Manufacturer 1">
<series title="Supercar" code="S1">
<model>
<name>Road Czar</name>
<code>C</code>
<year>2011</year>
</model>
<model>
<name>Ubervehicle</name>
<code>U</code>
<year>2013</year>
</model>
<model>
<name>Incredibulus</name>
<code>I</code>
<year>2015</year>
</model>
<model>
<name>Model 1</name>
<code>01</code>
<year>2010</year>
</model>
</series>
<series title="Test series 22" code="Test">
<model>
<name>Test model asdafds</name>
<code>TT</code>
<year>2014</year>
</model>
</series>
</manufacturer>
<manufacturer name="Car Corporation">
<series title="Corporation Car" code="CC">
<model>
<name>First and Only Model</name>
<code>FOM</code>
<year>2012</year>
</model>
</series>
</manufacturer>
<manufacturer name="Second Test Manufacturer">
<series title="AAAAAAAAAAAAAA" code="D">
<model>
<name>Some older model</name>
<code>O</code>
<year>2011</year>
</model>
<model>
<name>The newest model</name>
<code>N</code>
<year>2014</year>
</model>
</series>
<series title="BBBBBBBBBBBBBBB" code="asdf">
<model>
<name>Another newest model here</name>
<code>TT</code>
<year>2015</year>
</model>
</series>
</manufacturer>
</products>
Output
Your output is this string. It lists the car manufacturers in alphabetical order, followed by a colon and the number of series they make. Under each manufacturer, it lists the series name, model name, and code of each of their models, starting from the newest and going backward by year. Trailing whitespace and line breaks are acceptable, as long as your output looks similar to this when printed.
Car Corporation: 1 series
Corporation Car, First and Only Model (CC-FOM)
Second Test Manufacturer: 2 series
BBBBBBBBBBBBBBB, Another newest model here (asdf-TT)
AAAAAAAAAAAAAA, The newest model (D-N)
AAAAAAAAAAAAAA, Some older model (D-O)
Test Manufacturer 1: 2 series
Supercar, Incredibulus (S1-I)
Test series 22, Test model asdafds (Test-TT)
Supercar, Ubervehicle (S1-U)
Supercar, Road Czar (S1-C)
Supercar, Model 1 (S1-01)
Rules and Scoring
You may write either a function or full program. The lowest byte count wins, and standard loopholes are disallowed.
Note that the input is fixed: you don't need to support any other inputs than the one given here. Your program is allowed to return nonsense or even crash if the input is modified in any way. You may also ignore the input and hard-code the output, if desired. However, you may not use XML or HTML parser libraries or built-ins.
Would an HTML parser be allowed or would that be bending the rules? – Downgoat – 2015-09-09T00:01:49.107
12I never want to buy a car from this company. – kirbyfan64sos – 2015-09-09T00:19:12.013
1@vihan I'll (rather arbitrarily) decide that HTML parsers are not allowed either, since the two formats are so similar. – Zgarb – 2015-09-09T00:28:45.273
What about XSLT? ;) – Beta Decay – 2015-09-10T06:07:56.340
@BetaDecay I'm going to allow XSLT as an exception, since it would probably be very tedious and annoying not to use XML parsing operations in that language. :P And it won't compete with the CJam answer anyway. – Zgarb – 2015-09-10T16:58:45.303