如何在 FXML/XML 中表示幂和指数,例如 Unicode 字符“上标二”?
How can I represent powers and exponents such as Unicode character 'superscript two" in FXML/XML?
我的 FXML 文件采用 UTF-8 格式。
这是代码的相关部分:
<?xml version="1.0" encoding="UTF-8"?>
<Text fx:id="totalSqMGlassText" layoutX="573.0" layoutY="547.0" strokeType="OUTSIDE" strokeWidth="0.0" text="�xB2;" AnchorPane.bottomAnchor="57.0" AnchorPane.leftAnchor="573.0" />
我检查了 UTF-8 代码的二次方 here and here. Found this information about Unicode character "superscript two", i.e. the second power: "UTF-8 (hex) - 0xC2 0xB2 (c2b2)". I also read this question and answer on 。所以我尝试了这些:
�xC2;
e�xB2;
슲
&#c2b2;
甚至这个 :)
&#c2 b2;
如果我使用标准文本,一切正常,但如果我尝试使用上述特殊字符并转义,我会收到此异常:
javafx.fxml.LoadException:
...
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[142,121]
Message: The character reference must end with the ';' delimiter.
或这个
Caused by: javax.xml.stream.XMLStreamException: ParseError at
[row,col]:[142,118]
Message: A decimal representation must immediately follow the "&#" in a character reference.
每次我都使用分号(有一次我什至没有分号但有两个分号:))。
我认为第二个例外是显而易见的。在我的绝望中,我只是简单地尝试了几次盲目地输入正确的转义,所以我将转义用于十进制表示而不是十六进制(如果我错了请纠正我)。
所以我的问题是:
你知道我做错了什么吗?在那种情况下正确的转义和代码是什么?还有,通常通过 FXML/XML 表示幂和指数的正确方法是什么?提前谢谢你。
对于 Unicode SUPERSCRIPT TWO
(²),将 �xB2;
替换为 ²
。
我的 FXML 文件采用 UTF-8 格式。 这是代码的相关部分:
<?xml version="1.0" encoding="UTF-8"?>
<Text fx:id="totalSqMGlassText" layoutX="573.0" layoutY="547.0" strokeType="OUTSIDE" strokeWidth="0.0" text="�xB2;" AnchorPane.bottomAnchor="57.0" AnchorPane.leftAnchor="573.0" />
我检查了 UTF-8 代码的二次方 here and here. Found this information about Unicode character "superscript two", i.e. the second power: "UTF-8 (hex) - 0xC2 0xB2 (c2b2)". I also read this question and answer on �xC2;
e�xB2;
슲
&#c2b2;
甚至这个 :)
&#c2 b2;
如果我使用标准文本,一切正常,但如果我尝试使用上述特殊字符并转义,我会收到此异常:
javafx.fxml.LoadException:
...
Caused by: javax.xml.stream.XMLStreamException: ParseError at [row,col]:[142,121]
Message: The character reference must end with the ';' delimiter.
或这个
Caused by: javax.xml.stream.XMLStreamException: ParseError at
[row,col]:[142,118]
Message: A decimal representation must immediately follow the "&#" in a character reference.
每次我都使用分号(有一次我什至没有分号但有两个分号:))。 我认为第二个例外是显而易见的。在我的绝望中,我只是简单地尝试了几次盲目地输入正确的转义,所以我将转义用于十进制表示而不是十六进制(如果我错了请纠正我)。 所以我的问题是:
你知道我做错了什么吗?在那种情况下正确的转义和代码是什么?还有,通常通过 FXML/XML 表示幂和指数的正确方法是什么?提前谢谢你。
对于 Unicode SUPERSCRIPT TWO
(²),将 �xB2;
替换为 ²
。