0

I am trying to read some local XML files with XMLHttpRequest() method, however some RSS files are 'malformed' with problems like "Opening and ending tag mismatch" (and obviouslly I can't fix then).

When open this LOCAL '.XML' files in browser or with xmlHttp.open("GET",url,true); I got this response:

This page contains the following errors: error on line 6 at column 8: Opening >and ending tag mismatch: hr line 0 and body Below is a rendering of the page up to the first error. 301 Moved Permanently 301 Moved Permanently nginx/1.10.3

And than the 'original' code has just gone... If I open this files as .txt or .html I can see/get the content, but can't get xmlHttp.responseXml to parse it later. If I open then in original (external) URL everything is OK.

I tried force the response to be parsed as XML using xmlHttp.overrideMimeType('text/xml'); with no success.

The code I use is function readxml(url){ xmlHttp = new window.XMLHttpRequest(); xmlHttp.open("GET", url, false); xmlHttp.send(null); xmlDoc = xmlHttp.responseXML.documentElement; return xmlDoc; }

Any help in how can I just ''bypass'' this XML validation before I get file content?

edudoda
  • 128
  • 2
  • 10
  • You cannot override for malformed XML. You would need to fall back and parse this manually. – Bibberty Apr 11 '19 at 23:33
  • 1
    You say that you can "open this files as .txt or .html". So do so, repair the "XML", *then* parse it. Until you have well-formed XML, you don't really have XML, so you can't expect an XML parser to do any more than report how it's not well-formed. – kjhughes Apr 11 '19 at 23:51
  • @kjhughes thake this XML as an example: http://revistagloborural.globo.com/rss/ultimas/feed.xml I can read it, but when open it locally it shows: error on line 6 at column 8: Opening and ending tag mismatch: hr line 0 and body – edudoda Apr 12 '19 at 00:17
  • 2
    Notice how there is an `hr` in your posted error message yet not one in that feed.xml. That suggests that what you're reading is not that feed.xml file. It may well be an error message in HTML, which would fail to parse as well-formed XML if it contains tags such as `
    ` without matching end tags.
    – kjhughes Apr 12 '19 at 01:04
  • 1
    @kjhughes u r right, the real files are placed in `.../eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/as/resources/xml/` and some of then (just 4 out of 10) has this code: ` 301 Moved Permanently

    301 Moved Permanently


    nginx
    `
    – edudoda Apr 12 '19 at 15:50
  • I was opening and seeing old/other versions of the real files (which was in fact corrupted). Calling some sources with HTTPS rather than HTTP solve some broken files, other links no longer exist. Thank you for your time and help! – edudoda Apr 12 '19 at 16:23

0 Answers0