我正在从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>
答案 0 :(得分:1)
您的示例实际上是格式错误的:它以store
元素的开始标记结束。
<store>
<storeName>Castorama Poland</storeName>
<storeCode>45</storeCode>
<address>Chorzów: ul. Sportowa 31</address>
</store>
<store>
答案 1 :(得分: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的支持是通用的。
答案 2 :(得分:0)
通过添加:
修正了它echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";