Note that there are some explanatory texts on larger screens.

plurals
  1. POxml parse error: 'Invalid character'
    primarykey
    data
    text
    <p>I'm using the google weather api for a widget.</p> <p>All is fine and dandy except that today I encountered a problem that I cannot solve. When called with this location:</p> <p><a href="http://www.google.com/ig/api?weather=dunjkovec,medimurska,croatia&amp;hl=en" rel="nofollow">http://www.google.com/ig/api?weather=dunjkovec,medimurska,croatia&amp;hl=en</a></p> <p>I get this error:</p> <pre><code>XML parse error 9 'Invalid character' at line 1, column 169 (byte index 199) </code></pre> <p>I suspect that the problem is here: Nedelišće</p> <p>The code block is this one:</p> <pre><code>$parser = xml_parser_create('UTF-8'); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1); $ok = xml_parse_into_struct($parser, $data, $values); if (!$ok) { $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)", xml_get_error_code($parser), xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser), xml_get_current_byte_index($parser)); } </code></pre> <p>$data is the content of the xml and $values is empty.</p> <p>Can someone help me? Thank you very much!</p> <p>EDIT----------------------------------</p> <p>After reading Hussein's post I discovered that the problem is in the way the file gets retrieved.</p> <p>I tried file_get_contents and cURL. Both returns:</p> <p> that is the line that creates problems. Or so I thought! I tried this html_entity_decode($data,ENT_NOQUOTES,'UTF-8') and it wasn't working, so I made a discover, I can't echo the contents of the xml, I can only print_r them and see the results in the html source! With any other location in the world it works, only this one creates problems... I wanna cry :-(</p> <p>EDIT 2--------------------------------</p> <p>For anybody that cares. I fixed the problem with this lines of code after retrieving the xml file from the api:</p> <pre><code>$data = mb_convert_encoding($data, 'UTF-8', mb_detect_encoding($data, 'UTF-8, ISO-8859-1', true)); $data = html_entity_decode($data,ENT_NOQUOTES,'UTF-8'); </code></pre> <p>then parse the xml, it works like a charm. I marked hussein's answer because it got me on the right track.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload