0

我正在从 PHP 中以 xml 格式输出一些波兰语地址,但 Firefox 表示该 xml 格式不正确,因为地址中有 ó 等字符。如何输出这样的波兰字符并具有有效的 xml。我在 PHP 中使用这个头文件:

header('Content-type: text/xml');

我需要设置某种字符集吗?

这是 Firefox 给出的错误消息:

XML 解析错误:格式不正确 位置:Poland.php 第 1 行,第 635 列:

这是xml:

<data><stores><store><storeName>Castorama Poland</storeName><storeCode>59</storeCode><address>Bialystok: ul. Narodowych Sil Zbrojnych 13</address></store><store><storeName>Castorama Poland</storeName><storeCode>42</storeCode><address>Bielsko-Biala: ul. Warszawska 186</address></store><store><storeName>Castorama Poland</storeName><storeCode>27</storeCode><address>Bydgoszcz: ul. Szubinska 5</address></store><store><storeName>Castorama Poland</storeName><storeCode>43</storeCode><address>Bytom: Aleja Jana Nowaka-Jezioranskiego 27</address></store><store><storeName>Castorama Poland</storeName><storeCode>45</storeCode><address>Chorzw: ul. Sportowa 31</address></store><store><storeName>Castorama Poland</storeName><storeCode>47</storeCode><address>Cieszyn: ul. Liburnia 10</address></store><store><storeName>Castorama Poland</storeName><storeCode>48</storeCode><address>Czestochowa: ul. Jana Pawla II 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>30</storeCode><address>Elk: ul. Ciepla 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>9</storeCode><address>Gdansk: ul. Odyseusza 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>8</storeCode><address>Gdansk Oliwa: Al. Grunwaldzka 262</address></store><store><storeName>Castorama Poland</storeName><storeCode>72</storeCode><address>Gliwice: Pszczynska 315</address></store><store><storeName>Castorama Poland</storeName><storeCode>12</storeCode><address>Glog�w: ul. Ks. J. Poniatowskiego 10</address></store><store><storeName>Castorama Poland</storeName><storeCode>5</storeCode><address>Gniezno: ul. Palucka 1</address></store><store><storeName>Castorama Poland</storeName><storeCode>15</storeCode><address>Gorz�w Wielkopolski: ul. Czartoryskiego 1</address></store><store><storeName>Castorama Poland</storeName><storeCode>14</storeCode><address>Jelenia G�ra: Al. Jana Pawla II 11</address></store><store><storeName>Castorama Poland</storeName><storeCode>6</storeCode><address>Kalisz: ul. Tylna 17-23</address></store><store><storeName>Castorama Poland</storeName><storeCode>50</storeCode><address>Katowice: ul. Rozdzienskiego 198</address></store><store><storeName>Castorama Poland</storeName><storeCode>19</storeCode><address>Kedzierzyn Kozle: Al. Armii Krajowej 40</address></store><store><storeName>Castorama Poland</storeName><storeCode>24</storeCode><address>Kielce: ul. Wrzosowa 42</address></store><store><storeName>Castorama Poland</storeName><storeCode>28</storeCode><address>Koszalin: ul. Paderewskiego 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>35</storeCode><address>Krak�w: ul. Sosnowiecka 147</address></store><store><storeName>Castorama Poland</storeName><storeCode>36</storeCode><address>Krak�w: ul. Pilot�w 6</address></store><store><storeName>Castorama Poland</storeName><storeCode>37</storeCode><address>Krak�w: ul. Walerego Slawka 1</address></store><store><storeName>Castorama Poland</storeName><storeCode>39</storeCode><address>Krak�w: ul. Zakopianska 62</address></store><store><storeName>Castorama Poland</storeName><storeCode>16</storeCode><address>Legnica: ul. Roberta Schumana 9</address></store><store><storeName>Castorama Poland</storeName><storeCode>18</storeCode><address>Lubin: Al. Komisji Edukacji Narodowej 1</address></store><store><storeName>Castorama Poland</storeName><storeCode>71</storeCode><address>Lublin: Melgiewska 16 c</address></store><store><storeName>Castorama Poland</storeName><storeCode>44</storeCode><address>L�dz: ul. Wr�blewskiego 31</address></store><store><storeName>Castorama Poland</storeName><storeCode>46</storeCode><address>L�dz: ul. Wydawnicza 13</address></store><store><storeName>Castorama Poland</storeName><storeCode>49</storeCode><address>L�dz: ul. Sikorskiego 2/6</address></store><store><storeName>Castorama Poland</storeName><storeCode>38</storeCode><address>Minsk Mazowiecki: Stojadla, ul. Warszawska 63b</address></store><store><storeName>Castorama Poland</storeName><storeCode>40</storeCode><address>Nowy Targ: ul. Szaflarska 176</address></store><store><storeName>Castorama Poland</storeName><storeCode>58</storeCode><address>Nysa: ul. Zygmunta Krasinskiego 31</address></store><store><storeName>Castorama Poland</storeName><storeCode>22</storeCode><address>Opole: ul. Wiejska 141a</address></store><store><storeName>Castorama Poland</storeName><storeCode>26</storeCode><address>Ostrowiec Swietokrzyski: ul. Stefana Zeromskiego 13</address></store><store><storeName>Castorama Poland</storeName><storeCode>64</storeCode><address>Oswiecim: ul. Zatorska 1</address></store><store><storeName>Castorama Poland</storeName><storeCode>4</storeCode><address>Poznan: ul. Murawa 39</address></store><store><storeName>Castorama Poland</storeName><storeCode>62</storeCode><address>Poznan: ul. Grecka 30A</address></store><store><storeName>Castorama Poland</storeName><storeCode>53</storeCode><address>Przemysl: ul. Lwowska 17</address></store><store><storeName>Castorama Poland</storeName><storeCode>52</storeCode><address>Racibrz: ul. Rybnicka 95</address></store><store><storeName>Castorama Poland</storeName><storeCode>11</storeCode><address>Rumia: ul. Grunwaldzka 5</address></store><store><storeName>Castorama Poland</storeName><storeCode>73</storeCode><address>Rybnik: Obwiednia Plnocna 21</address></store><store><storeName>Castorama Poland</storeName><storeCode>55</storeCode><address>Rzeszw: Al. Rejtana 67</address></store><store><storeName>Castorama Poland</storeName><storeCode>76</storeCode><address>Skarzysko-Kamienna: Al. Jzefa Pilsudskiego 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>51</storeCode><address>Skierniewice: ul. Wyszynskiego 10</address></store><store><storeName>Castorama Poland</storeName><storeCode>13</storeCode><address>Slupsk: ul. Hubalczykw 2</address></store><store><storeName>Castorama Poland</storeName><storeCode>54</storeCode><address>Sosnowiec: ul. Dlugosza 82</address></store><store><storeName>Castorama Poland</storeName><storeCode>7</storeCode><address>Stare Miasto kolo Konina: ul. Ogrodowa 31</address></store><store><storeName>Castorama Poland</storeName><storeCode>61</storeCode><address>Stargard Szczecinski: ul. Tadeusza Kosciuszki 73a</address></store><store><storeName>Castorama Poland</storeName><storeCode>63</storeCode><address>Swarzedz: Sienkiewicza 23</address></store><store><storeName>Castorama Poland</storeName><storeCode>31</storeCode><address>Szczecin: ul. Ku Sloncu 67b</address></store><store><storeName>Castorama Poland</storeName><storeCode>33</storeCode><address>Szczecin: ul. Poludniowa 21</address></store><store><storeName>Castorama Poland</storeName><storeCode>34</storeCode><address>Szczecin: ul. Wiosenna 80</address></store><store><storeName>Castorama Poland</storeName><storeCode>56</storeCode><address>Tarnowskie Gry: ul. Obwodnica 16</address></store><store><storeName>Castorama Poland</storeName><storeCode>41</storeCode><address>Tarnw: ul. Nowodabrowska 127</address></store><store><storeName>Castorama Poland</storeName><storeCode>29</storeCode><address>Torun: ul. Szosa Bydgoska 102 A</address></store><store><storeName>Castorama Poland</storeName><storeCode>20</storeCode><address>Walbrzych: ul. H. Wieniawskiego 21</address></store><store><storeName>Castorama Poland</storeName><storeCode>1</storeCode><address>Warszawa: ul. Popularna 71</address></store><store><storeName>Castorama Poland</storeName><storeCode>2</storeCode><address>Warszawa: Al. Krakowska 75</address></store><store><storeName>Castorama Poland</storeName><storeCode>3</storeCode><address>Warszawa: ul. Glebocka 15a</address></store><store><storeName>Castorama Poland</storeName><storeCode>74</storeCode><address>Warszawa: ul. Grochowska 21</address></store><store><storeName>Castorama Poland</storeName><storeCode>21</storeCode><address>Wroclaw: ul. Graniczna 2a</address></store><store><storeName>Castorama Poland</storeName><storeCode>23</storeCode><address>Wroclaw: ul. B. Krzywoustego 126a</address></store></stores><feedData><executionTimeInSeconds>0.0006</executionTimeInSeconds><numberOfCastoramaPolandStores>69</numberOfCastoramaPolandStores></feedData></data>
4

3 回答 3

1

您的示例实际上格式错误:它以store元素的开始标记结尾。

<store>
 <storeName>Castorama Poland</storeName>
 <storeCode>45</storeCode>
 <address>Chorzów: ul. Sportowa 31</address>
 </store>
<store>
于 2013-11-08T17:17:23.400 回答
0

如果 XML 片段无法解析,则可能是因为字符编码不是 XML 解析器认为的那样。如果文件开头没有 XML 声明,那么 Firefox 将采用 UTF-8,或者它可能(我不确定)尝试使用来自 HTTP 标头的编码信息。最好的办法是:

a) 确保文件以 UTF-8 编码

b) 确保它有一个 XML 声明,表明它是用 UTF-8 编码的

c) 确保使用 MIME 类型的 application/xml 提供服务(不是 text/xml,这可能会导致它在传输时被错误地转码)

如果现有文件是其他编码,例如 ISO 8859-2,那么您可以尝试以该编码将其发送到浏览器,但这依赖于支持该编码的浏览器,而对 UTF-8 的支持是通用的。

于 2013-11-08T17:14:42.590 回答
0

通过添加修复它:

echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
于 2013-11-08T18:44:24.220 回答