Pure Programmer
Blue Matrix


Cluster Map

Project: XML Encoding Filter

Write a filter program that transforms the input Unicode text stream into properly encoded XML. The characters left angle bracket, right angle bracket, ampersand, apostrophe and double quotes need to be converted to their corresponding XML entities <, >, &, ' and ". Any codepoint higher than 127 should be encoded as a hexadecimal character entity such as ሴ.

See [[List of XML and HTML character entity references]]

Output
$ python XMLEncodingFilter.py < ../../data/html/Minimal.html &lt;html lang=&apos;en&apos;&gt; &lt;head&gt; &lt;title&gt;Title Page&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 align=&quot;center&quot;&gt;Headline&lt;/h1&gt; &lt;p&gt;Body text &amp;#9786;&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; $ python XMLEncodingFilter.py < ../../data/text/UnicodeTest.utf8 Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal. Vor vier Punkten und sieben Jahren haben unsere V&#x00e4;ter auf diesem Kontinent eine neue Nation hervorgebracht, die in Freiheit empfangen wurde und sich dem Vorschlag verschrieben hat, dass alle Menschen gleich geschaffen sind. &#x03a4;&#x03ad;&#x03c3;&#x03c3;&#x03b5;&#x03c1;&#x03b1; &#x03c3;&#x03ba;&#x03bf;&#x03c1; &#x03ba;&#x03b1;&#x03b9; &#x03c0;&#x03c1;&#x03b9;&#x03bd; &#x03b1;&#x03c0;&#x03cc; &#x03b5;&#x03c0;&#x03c4;&#x03ac; &#x03c7;&#x03c1;&#x03cc;&#x03bd;&#x03b9;&#x03b1; &#x03bf;&#x03b9; &#x03c0;&#x03b1;&#x03c4;&#x03ad;&#x03c1;&#x03b5;&#x03c2; &#x03bc;&#x03b1;&#x03c2; &#x03ad;&#x03c6;&#x03b5;&#x03c1;&#x03b1;&#x03bd; &#x03c3;&#x03b5; &#x03b1;&#x03c5;&#x03c4;&#x03ae; &#x03c4;&#x03b7;&#x03bd; &#x03ae;&#x03c0;&#x03b5;&#x03b9;&#x03c1;&#x03bf;, &#x03ad;&#x03bd;&#x03b1; &#x03bd;&#x03ad;&#x03bf; &#x03ad;&#x03b8;&#x03bd;&#x03bf;&#x03c2;, &#x03c0;&#x03bf;&#x03c5; &#x03c3;&#x03c7;&#x03b5;&#x03b4;&#x03b9;&#x03ac;&#x03c3;&#x03c4;&#x03b7;&#x03ba;&#x03b5; &#x03c3;&#x03c4;&#x03b7;&#x03bd; &#x0395;&#x03bb;&#x03b5;&#x03c5;&#x03b8;&#x03b5;&#x03c1;&#x03af;&#x03b1; &#x03ba;&#x03b1;&#x03b9; &#x03b1;&#x03c6;&#x03b9;&#x03b5;&#x03c1;&#x03ce;&#x03b8;&#x03b7;&#x03ba;&#x03b5; &#x03c3;&#x03c4;&#x03b7;&#x03bd; &#x03c0;&#x03c1;&#x03cc;&#x03c4;&#x03b1;&#x03c3;&#x03b7; &#x03cc;&#x03c4;&#x03b9; &#x03cc;&#x03bb;&#x03bf;&#x03b9; &#x03bf;&#x03b9; &#x03ac;&#x03bd;&#x03b8;&#x03c1;&#x03c9;&#x03c0;&#x03bf;&#x03b9; &#x03b4;&#x03b7;&#x03bc;&#x03b9;&#x03bf;&#x03c5;&#x03c1;&#x03b3;&#x03bf;&#x03cd;&#x03bd;&#x03c4;&#x03b1;&#x03b9; &#x03af;&#x03c3;&#x03bf;&#x03b9;. &#x0623;&#x0631;&#x0628;&#x0639; &#x0646;&#x0642;&#x0627;&#x0637; &#x0648;&#x0642;&#x0628;&#x0644; &#x0633;&#x0628;&#x0639; &#x0633;&#x0646;&#x0648;&#x0627;&#x062a; &#x0642;&#x062f;&#x0645; &#x0622;&#x0628;&#x0627;&#x0624;&#x0646;&#x0627; &#x0641;&#x064a; &#x0647;&#x0630;&#x0647; &#x0627;&#x0644;&#x0642;&#x0627;&#x0631;&#x0629; &#x060c; &#x0623;&#x0645;&#x0629; &#x062c;&#x062f;&#x064a;&#x062f;&#x0629; &#x060c; &#x062a;&#x0645; &#x062a;&#x0635;&#x0648;&#x0631;&#x0647;&#x0627; &#x0641;&#x064a; &#x0627;&#x0644;&#x062d;&#x0631;&#x064a;&#x0629; &#x060c; &#x0648;&#x0645;&#x0643;&#x0631;&#x0633;&#x0629; &#x0644;&#x0641;&#x0631;&#x0636;&#x064a;&#x0629; &#x0623;&#x0646; &#x062c;&#x0645;&#x064a;&#x0639; &#x0627;&#x0644;&#x0631;&#x062c;&#x0627;&#x0644; &#x062e;&#x0644;&#x0642;&#x0648;&#x0627; &#x0645;&#x062a;&#x0633;&#x0627;&#x0648;&#x064a;&#x0646;. &#x05d0;&#x05e8;&#x05d1;&#x05e2; &#x05e6;&#x05d9;&#x05d5;&#x05e0;&#x05d9;&#x05dd; &#x05d5;&#x05dc;&#x05e4;&#x05e0;&#x05d9; &#x05e9;&#x05d1;&#x05e2; &#x05e9;&#x05e0;&#x05d9;&#x05dd; &#x05d0;&#x05d1;&#x05d5;&#x05ea;&#x05d9;&#x05e0;&#x05d5; &#x05d4;&#x05e6;&#x05d9;&#x05d2;&#x05d5; &#x05d1;&#x05d9;&#x05d1;&#x05e9;&#x05ea; &#x05d6;&#x05d5;, &#x05d0;&#x05d5;&#x05de;&#x05d4; &#x05d7;&#x05d3;&#x05e9;&#x05d4;, &#x05e9;&#x05d4;&#x05d2;&#x05ea;&#x05d4; &#x05d1;&#x05d7;&#x05d9;&#x05e8;&#x05d5;&#x05ea;, &#x05d5;&#x05d4;&#x05d5;&#x05e7;&#x05d3;&#x05e9;&#x05d4; &#x05dc;&#x05d8;&#x05e2;&#x05e0;&#x05d4; &#x05e9;&#x05db;&#x05dc; &#x05d4;&#x05d2;&#x05d1;&#x05e8;&#x05d9;&#x05dd; &#x05e0;&#x05d5;&#x05e6;&#x05e8;&#x05d9;&#x05dd; &#x05e9;&#x05d5;&#x05d5;&#x05d9;&#x05dd;. 4&#x30b9;&#x30b3;&#x30a2;&#x3068;7&#x5e74;&#x524d;&#x3001;&#x79c1;&#x305f;&#x3061;&#x306e;&#x7236;&#x89aa;&#x306f;&#x3001;&#x3053;&#x306e;&#x5927;&#x9678;&#x3067;&#x751f;&#x307e;&#x308c;&#x305f;&#x65b0;&#x3057;&#x3044;&#x56fd;&#x3067;&#x3042;&#x308a;&#x3001;&#x30ea;&#x30d0;&#x30c6;&#x30a3;&#x3067;&#x8003;&#x6848;&#x3055;&#x308c;&#x3001;&#x3059;&#x3079;&#x3066;&#x306e;&#x4eba;&#x304c;&#x5e73;&#x7b49;&#x306b;&#x5275;&#x9020;&#x3055;&#x308c;&#x308b;&#x3068;&#x3044;&#x3046;&#x547d;&#x984c;&#x306b;&#x732e;&#x8eab;&#x3057;&#x307e;&#x3057;&#x305f;&#x3002; 4 &#xc810; 7 &#xb144; &#xc804;, &#xc6b0;&#xb9ac; &#xc870;&#xc0c1;&#xb4e4;&#xc740; &#xb9ac;&#xbc84;&#xd2f0;&#xc5d0;&#xc11c; &#xc789;&#xd0dc; &#xb41c; &#xc0c8;&#xb85c;&#xc6b4; &#xad6d;&#xac00; &#xc778;&#xc774; &#xb300;&#xb959;&#xc5d0;&#xc11c; &#xbaa8;&#xb4e0; &#xc0ac;&#xb78c;&#xb4e4;&#xc774; &#xd3c9;&#xb4f1;&#xd558;&#xac8c; &#xcc3d;&#xc870;&#xb418;&#xc5c8;&#xb2e4;&#xace0; &#xc81c;&#xc548;&#xd588;&#xc2b5;&#xb2c8;&#xb2e4;. &#x56db;&#x5e74;&#x524d;&#x4e03;&#x5e74;&#x524d;&#xff0c;&#x6211;&#x4eec;&#x7684;&#x7956;&#x5148;&#x5728;&#x8fd9;&#x4e2a;&#x5927;&#x9646;&#x4e0a;&#x5efa;&#x7acb;&#x4e86;&#x4e00;&#x4e2a;&#x65b0;&#x56fd;&#x5bb6;&#xff0c;&#x8fd9;&#x4e2a;&#x56fd;&#x5bb6;&#x662f;&#x5728;&#x81ea;&#x7531;&#x4e2d;&#x5b55;&#x80b2;&#x7684;&#xff0c;&#x81f4;&#x529b;&#x4e8e;&#x5b9e;&#x73b0;&#x4eba;&#x4eba;&#x5e73;&#x7b49;&#x7684;&#x4e3b;&#x5f20;&#x3002; Unicode 11 Emoji &#x1f970; Smiling Face with Hearts &#x1f975; Hot Face &#x1f976; Cold Face &#x1f974; Woozy Face &#x1f973; Partying Face Unicode 10 Emoji &#x1f92a; Zany Face &#x1f92f; Exploding Head &#x1f9d0; Face with Monocle &#x1f92c; Face with Symbols on Mouth &#x1f996; T-Rex Unicode 9 Emoji &#x1f923; Rolling on the Floor Laughing &#x1f922; Nauseated Face &#x1f921; Clown Face &#x1f98a; Fox &#x1f988; Shark Unicode 8 Emoji &#x1f911; Money-Mouth Face &#x1f913; Nerd Face &#x1f981; Lion &#x1f984; Unicorn &#x1f980; Crab Unicode 7 Emoji &#x1f596; Vulcan Salute &#x1f43f; Chipmunk &#x1f577; Spider &#x1f336; Hot Pepper &#x1f32a; Tornado Precomposed vs. Decomposed &#x00c5; = A&#x030a; &#x00e0; = a&#x0300; &#x00e9; = e&#x0301; &#x00ee; = i&#x0302; &#x00f1; = n&#x0303; &#x00fc; = u&#x0308; &#xd55c; = &#x1112;&#x1161;&#x11ab; Graphemes that take two codepoints Canada &#x1f1e8;&#x1f1e6; China &#x1f1e8;&#x1f1f3; France &#x1f1eb;&#x1f1f7; Greece &#x1f1ec;&#x1f1f7; Israel &#x1f1ee;&#x1f1f1; Japan &#x1f1ef;&#x1f1f5; Mexico &#x1f1f2;&#x1f1fd; UK &#x1f1ec;&#x1f1e7; US &#x1f1fa;&#x1f1f8;

Solution