{"id":548,"date":"2022-11-29T20:11:27","date_gmt":"2022-11-29T20:11:27","guid":{"rendered":"http:\/\/qedevelopment.co.uk\/?p=548"},"modified":"2022-11-29T20:12:28","modified_gmt":"2022-11-29T20:12:28","slug":"emacs-how-to-format-and-xml-file","status":"publish","type":"post","link":"https:\/\/qedevelopment.co.uk\/?p=548","title":{"rendered":"Emacs: How to Format an XML file"},"content":{"rendered":"\n<p>Using emacs in conjunction with libxml2 it is possible to quickly format an xml file into a more readable format. For the purposes of this example we will take the following xml file and reformat it. NB libxml2 must be installed on your machine<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;Tests xmlns=\"http:\/\/www.qedevelopment.co.uk\"&gt;\n  &lt;Test Id=\"0001\" Type=\"foo\"&gt;\n    &lt;Name&gt;Foo test&lt;\/Name&gt;\n    &lt;Input&gt;1&lt;\/Input&gt;\n    &lt;Output&gt;One&lt;\/Output&gt;\n  &lt;\/Test&gt;\n  &lt;Test Id=\"0002\" Type=\"garp\"&gt;&lt;Name&gt;Garp test&lt;\/Name&gt;&lt;Input&gt;abc&lt;\/Input&gt;&lt;Output&gt;def&lt;\/Output&gt;&lt;\/Test&gt;\n&lt;\/Tests&gt;<\/code><\/pre>\n\n\n\n<p>Enter the following command into emacs. Where C-x h represents the pressing of the &lt;ctrl&gt; key and the &#8216;x&#8217; key at the same time followed by the &#8216;h&#8217; key in order to select all the text in the buffer. M-| represents the pressing of the &lt;esc&gt; key followed by the &#8216;|&#8217; key (not the simultaneous pressing of the two keys). The RET represents the return key, and don&#8217;t forget the &#8216;-&#8216; between it and the format.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>C-x h C-u M-| xmllint --format - RET<\/code><\/pre>\n\n\n\n<p id=\"block-c6dcab0a-9ec2-4976-826d-e5e52a498e70\">You contents of the buffer should now have been reformatted as show below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?xml version=\"1.0\"?&gt;\n&lt;Tests xmlns=\"http:\/\/www.qedevelopment.co.uk\"&gt;\n  &lt;Test Id=\"0001\" Type=\"foo\"&gt;\n    &lt;Name&gt;Foo test&lt;\/Name&gt;\n    &lt;Input&gt;1&lt;\/Input&gt;\n    &lt;Output&gt;One&lt;\/Output&gt;\n  &lt;\/Test&gt;\n  &lt;Test Id=\"0002\" Type=\"garp\"&gt;\n    &lt;Name&gt;Garp test&lt;\/Name&gt;\n    &lt;Input&gt;abc&lt;\/Input&gt;\n    &lt;Output&gt;def&lt;\/Output&gt;\n  &lt;\/Test&gt;\n&lt;\/Tests&gt;\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using emacs in conjunction with libxml2 it is possible to quickly format an xml file into a more readable format. For the purposes of this example we will take the following xml file and reformat it. NB libxml2 must be installed on your machine Enter the following command into emacs. Where C-x h represents the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/qedevelopment.co.uk\/?p=548\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Emacs: How to Format an XML file&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_mi_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0},"categories":[1],"tags":[],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/548"}],"collection":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=548"}],"version-history":[{"count":4,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions"}],"predecessor-version":[{"id":552,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=\/wp\/v2\/posts\/548\/revisions\/552"}],"wp:attachment":[{"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/qedevelopment.co.uk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}