【问题标题】:special characters is not allow in xml file in asset folder in AndroidAndroid资产文件夹中的xml文件中不允许使用特殊字符
【发布时间】:2014-09-23 09:44:25
【问题描述】:

如何在 Android.org.apache.harmony.xml.ExpatParser$ParseException 的 Asset 文件夹中的 xml 文件中格式正确:在第 19 行,第 24 列:格式不正确(无效令牌) 在 org.apache.harmony.xml.ExpatParser.parseFragment(ExpatParser.java:520) 在 org.apache.harmony.xml.ExpatParser.parseDocument(ExpatParser.java:479)

这里是xml文件

<?xml version="1.0" encoding="UTF-8"?>
<menu>
   <item>
        <QNO>50</QNO>    
        <QUESTIONS>Which declaration of the main method below would allow a class to be started as a standalone program. Select the one correct answer.</QUESTIONS>
        <ANSWER>35,35</ANSWER>
        <OPTIONA>35,35</OPTIONA>
        <OPTIONB>35,40</OPTIONB>
        <OPTIONC>36,32</OPTIONC>
        <OPTIOND>None of these</OPTIOND>
        <EXPLAINATION>NONE</EXPLAINATION>       
        <QUESTIONTYPE>JAVA</QUESTIONTYPE>
    </item>
<item>
        <QNO>49</QNO>    
        <QUESTIONS>What all gets printed when the following code is compiled and run? Select the three correct answers.
 public class xyz {
   public static void main(String args[]) {
      for(int i = 0; i < 2; i++) {
         for(int j = 2; j>= 0; j--) {
            if(i == j) break;
            System.out.println("i=" + i + " j="+j);
         }
      }
   }
}</QUESTIONS>
        <ANSWER>35,35</ANSWER>
        <OPTIONA>35,35</OPTIONA>
        <OPTIONB>35,40</OPTIONB>
        <OPTIONC>36,32</OPTIONC>
        <OPTIOND>None of these</OPTIOND>
        <EXPLAINATION>NONE</EXPLAINATION>       
        <QUESTIONTYPE>JAVA</QUESTIONTYPE>
    </item>
<item>
<menu>

在第 19 行,第 24 列 =public static void main(String args[]) {for(int i = 0; i

【问题讨论】:

  • &amp;lt;&amp;amp; 字符在 XML 内容中是严格非法的,另外替换这两个字符也是一个好习惯:&amp;lt; = &amp;lt;, &amp;gt; = &gt;, &amp;amp; = &amp;amp;, &amp;apos; = ', &amp;quot;=".

标签: android xml


【解决方案1】:

代码 sn-p 包含&amp;lt;,它也是用于开始标记的 XML 元字符。

要么将&amp;lt; 替换为&amp;lt;,要么将代码包装在未解析的CDATA 块中:

<![CDATA[ ... ]]>

【讨论】:

  • :谢谢回复。你能告诉我在上面的xml文件中如何以及在哪里使用这个标签。
  • 我使用了你的代码行,但我的标签没有显示在屏幕上。
  • :like this 编译和运行以下代码时会打印什么?选出三个正确答案。公共类 xyz { public static void main(String args[]) { for(int i = 0; i = 0; j--) { if(i = = j) 中断; System.out.println("i=" + i + " j="+j); } } } }]]>
【解决方案2】:
 i=0 j=2
 i=0 j=1
 i=1 j=2

;-)。

【讨论】:

  • 你不明白我的问题或帖子。我说的是如何编写 编译和运行以下代码时会打印什么?选出三个正确答案。公共类 xyz { public static void main(String args[]) { for(int i = 0; i = 0; j--) { if(i = = j) 中断; System.out.println("i=" + i + " j="+j); } } } } xml 中的这个标签格式很好,带有特殊字符。我不想输出。
  • 开个玩笑,但不是答案。
猜你喜欢
  • 2014-12-28
  • 1970-01-01
  • 1970-01-01
  • 2011-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-02-23
  • 1970-01-01
相关资源
最近更新 更多