(一些)HTML實體破壞XSL引擎是正常的嗎?

[英]Is it normal that (some) HTML entities are breaking the XSL engine?


I have a dynamically generated XML document made with PHP DOMDocument. I use this XML with an XSL file. It worked fine until I got the Yen currency symbol (¥) from a database entry. This symbol is escaped to the ¥ HTML entity. This entity is breaking the XSL/XML engine:

我有一個用PHP DOMDocument生成的動態生成的XML文檔。我在XSL文件中使用這個XML。它工作得很好,直到我得到了日元貨幣符號(¥)從數據庫條目。這個符號被轉義到日元;HTML實體。這個實體正在破壞XSL/XML引擎:

Warning: DOMDocument::load() [domdocument.load]: Entity 'yen' not defined in %file.xml%, line: %1% in %file.php% on line %2%

警告:DOMDocument:負載(DOMDocument()。:在%文件中未定義的實體'yen'。xml%,行:%1%文件。行php % % 2%

When the ¥ entity is not there everything works well.

當円實體不是一切都運作良好。

Is there something I haven't done/included/configured to get this error?

有什么是我沒有做/包括/配置的,以得到這個錯誤?

3 个解决方案

#1


3  

XML only recognizes a few character entities: &lt;, &gt; &quot;, &amp;, &apos;. Anything else would be a parsing error unless you add in definitions for the entities yourself: <!ENTITY yen "&#x00a5">

XML只識別一些字符實體:< >事情就讓它“,,,,。除非您自己為實體添加定義:

#2


2  

With &yen; your XML becomes not well-formed XML, because XML doesn't have predefined &yen; entity. Valid escape version of ¥ is &#xA5;.

與円您的XML變得不是格式良好的XML,因為XML沒有預定義的¥實體。有效逃避版¥& # xA5;。

#3


1  

When it comes to working with XML, the only entities that are defined by default are &amp;, &lt; and &gt;. Any other entities need to be defined in the DTD.

在使用XML時,唯一默認定義的實體是& & & <和祝辭。任何其他實體都需要在DTD中定義。

XSL does not define any other entities in its doctype. Even if you're converting to (x)HTML, you don't have those other entities defined because your primary doctype is for XSL.

XSL沒有在其doctype中定義任何其他實體。即使要轉換到(x)HTML,也沒有定義其他實體,因為主要的doctype是針對XSL的。

You could add a big bunch of declarations to define them in the DTD, but this would mean using a custom DTD, which isn't ideal, and is also a lot of work to maintain.

您可以在DTD中添加大量的聲明來定義它們,但是這意味着使用定制的DTD,這並不理想,而且還需要大量的工作來維護。

Frankly, the easiest solution to this is simply to use numeric entity code for everything. It's a pain, but it works in any XML dialect without needing any hacking with the DTD.

坦率地說,最簡單的解決方案就是對所有東西都使用數字實體代碼。這很痛苦,但它可以在任何XML方言中工作,而不需要對DTD進行任何修改。


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2011/07/22/725038e8909e3c546e6609a0a2ad95e4.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com