how to generate XML sitemap with special symbols in the link?

倾然丶 夕夏残阳落幕 提交于 2020-01-05 12:13:41

问题


Hi I am trying to generate google sitemap for my site, how can i make link to contain special symbols like below:

<url>
   <loc>http://example.com/alf-“xxx-yyy”--cache</loc>
</url>

how can i handle such characters??? i have tried urlencode but this doesn't work :(( Thanks for your help


回答1:


The special characters that you are referring to are the directional curly quotes and . You can use the numeric entity reference for those characters &#8220; and &#8221;, respectively.

http://www.dwheeler.com/essays/quotes-in-html.html

If you’re creating HTML, SGML, and XML directly, perhaps using a text editor or writing a program, always use “decimal numeric character references” for curling single and double quote characters (these marks are called “smart quotes,” “curly quotes,” “curled quotes,” “curling quotes,” or “curved quotes”).

In other words, for left and right double quotation marks, use &#8220; and &#8221; - and for left and right single quotation marks (and apostrophes), use &#8216; and &#8217; - and you’ll be glad you did. This approach complies with all international standards, and works essentially everywhere.

Left Double Quotation Mark   =   &#8220; = “
Right Double Quotation Mark =   &#8221; = ”
Left Single Quotation Mark   =   &#8216; = ‘
Right Single Quotation Mark =   &#8217; = ’

By doing this, your text will look good on a very wide variety of browsers and viewers, and you can easily cut-and-paste portions of data between HTML, SGML, and XML documents (letting you dynamically query and create new material from existing material, without having to deal with the complexities of translating between character sets).




回答2:


XML has five predefined entities.

In your example, you need to represent the quotes as &quot;.

<url>
<loc>http://example.com/alf-&quot;xxx-yyy&quot;--cache</loc>
</url>



来源:https://stackoverflow.com/questions/4483340/how-to-generate-xml-sitemap-with-special-symbols-in-the-link

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!