{"id":491,"date":"2018-05-17T12:12:18","date_gmt":"2018-05-17T16:12:18","guid":{"rendered":"http:\/\/www.tayloraliss.com\/blog\/?p=491"},"modified":"2018-05-17T12:12:18","modified_gmt":"2018-05-17T16:12:18","slug":"automatically-downloading-xml-from-chrome","status":"publish","type":"post","link":"https:\/\/www.tayloraliss.com\/blog\/?p=491","title":{"rendered":"Automatically Downloading XML from Chrome"},"content":{"rendered":"<p>I recently was given the task of gathering data from several xml files that were automatically generated based on search queries. After going through the first few files, I realized that my current process was quite inefficient. I started by clicking the link to the xml data, which would then render inside of Google Chrome. It looked something like this (although the actual xml files were <em>much<\/em> longer):<br \/>\n<a href=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.42.22-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-492 size-full\" src=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.42.22-AM.png\" alt=\"\" width=\"753\" height=\"424\" srcset=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.42.22-AM.png 753w, https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.42.22-AM-300x169.png 300w\" sizes=\"auto, (max-width: 753px) 100vw, 753px\" \/><\/a>I would then use\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">ctrl+f<\/code>\u00a0to look for the piece of data I needed. This was a painfully slow process, as I had to find a lot of data, and often the xml nodes had the same names but in different places. This lead to a lot of wasted time double and triple-checking that the data I was looking at was the\u00a0<em>correct\u00a0<\/em>data. I figured there had to be a better way.<\/p>\n<p>It was about this time that I learned about\u00a0<a href=\"https:\/\/www.w3schools.com\/xml\/xpath_intro.asp\">XPath<\/a>, which I figured could do a lot to speed up the process. Unfortunately, Chrome&#8217;s default xml viewer doesn&#8217;t support XPath, so I figured there must be a plugin out there that does. I started by trying out the <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/xv-%E2%80%94-xml-viewer\/eeocglpgjdpaefaedpblffpeebgmgddk?hl=en\">XV XML Viewer<\/a> plugin, but it seemed to still be in slow development and the XPath support was really lacking. In addition, it made it difficult to copy+paste XML as that feature had been disabled in a recent release. I also learned about the excellent plugin <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/chropath\/ljngjbnaijcbncmcnjfhigebomdlkcjo?hl=en\">ChroPath<\/a> which supports XPath, but really only for DOM manipulation. It didn&#8217;t work very well on the XML pages rendered in Chrome.<\/p>\n<p>After spending a\u00a0<em>lot<\/em> of time trying out various Chrome plugins, I remembered that <a href=\"https:\/\/code.visualstudio.com\/\">VS Code<\/a> has XPath functionality built right into it. Now all I needed to do was open the file in Chrome, copy+paste it into VS Code and I could use XPath to my heart&#8217;s delight&#8230; except that when you copy+paste from Chrome, it includes all of the HTML Chrome adds to display the XML, and you have to spend extra time removing it all. Ugh.<\/p>\n<p>I tried to see if there was a way to get Chrome to display XML as plain text, instead of rendering it inside an HTML document. I couldn&#8217;t find one. The only alternative was to right-clicking the document after it loaded and save it to my desktop. This annoyed me because I would rather Chrome not open the file at all and just download it straight-away. After lots of research online, I\u00a0<em>finally<\/em> figured out how to enable this functionality.<\/p>\n<p>First, I needed to intercept the HTTP response from the server change the variables in the header so Chrome wouldn&#8217;t know that it was receiving an XML document. I also had to inform Chrome that this file should be downloaded, and that Chrome shouldn&#8217;t attempt to open it. To do this, I downloaded the plugin <a href=\"https:\/\/chrome.google.com\/webstore\/detail\/modheader\/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en-US\">ModHeader<\/a>\u00a0and gave it the following settings:<a href=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.12.53-AM.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-493 size-full\" src=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.12.53-AM.png\" alt=\"\" width=\"596\" height=\"315\" srcset=\"https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.12.53-AM.png 596w, https:\/\/www.tayloraliss.com\/blog\/wp-content\/uploads\/2018\/05\/Screen-Shot-2018-05-17-at-11.12.53-AM-300x159.png 300w\" sizes=\"auto, (max-width: 596px) 100vw, 596px\" \/><\/a>Now whenever I encountered a file with a Content-Type of xml on that specific domain, ModHeader would intercept its response header and change it to\u00a0<code class=\"EnlighterJSRAW\" data-enlighter-language=\"no-highlight\">application\/octet-stream<\/code>\u00a0which is sort of just a generic type. It would then label the file as an attachment which means it is to be downloaded, and give it a file name.\u00a0Voil\u00e0! Files automatically downloaded!<\/p>\n<p>Next I told Chrome to just open .xml files automatically with my system&#8217;s default program, and they show up instantly in VS Code! I can now access XML files and run XPath searches on them instantly and am able to save a ton of time. Good stuff.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently was given the task of gathering data from several xml files that were automatically generated based on search queries. After going through the first few files, I realized that my current process was quite inefficient. I started by clicking the link to the xml data, which would then render inside of Google Chrome. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-491","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=491"}],"version-history":[{"count":1,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions"}],"predecessor-version":[{"id":494,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/491\/revisions\/494"}],"wp:attachment":[{"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=491"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=491"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tayloraliss.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=491"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}