Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java XML字符<;Unicode:0xc>;在文档的元素内容中找到_Java_Xml_Pdf_Netbeans - Fatal编程技术网

Java XML字符<;Unicode:0xc>;在文档的元素内容中找到

Java XML字符<;Unicode:0xc>;在文档的元素内容中找到,java,xml,pdf,netbeans,Java,Xml,Pdf,Netbeans,我正在从java应用程序上的SQL查询生成pdf。 我有400万张pdf要打印 在第15092页pdf。 我遇到了这个错误 Invalid xml character (unicode 0xc) was found in the element content of the document 我试图取代其他博客所说的内容 html = html.replaceAll("\000"," "); html = html.replaceAll("/\u000c+/g", "");

我正在从java应用程序上的SQL查询生成pdf。 我有400万张pdf要打印

在第15092页pdf。 我遇到了这个错误

Invalid xml character (unicode 0xc) was found in the element content of the document
我试图取代其他博客所说的内容

    html = html.replaceAll("\000"," ");
    html = html.replaceAll("/\u000c+/g", "");
我不知道哪个是哪个,我只是把它们放在我的html中

有人有想法吗


谢谢

有几种替换方法。我更详细地描述了它们,因为我认为理解它们比复制代码更重要

  • 一个简单的逐字符替换。这适用于您的情况,因为您只想替换某个字符的出现。由于您的角色是控制角色,因此(通常)无法直接插入,只能通过以下方式之一插入:

    • Unicode引用:
      html=html.replace('\u000c','');//十六进制值==0xc
    • 八进制引用:
      html=html.replace('\14','');//0xc==014
    • 根据其含义:
      html=html.replace('\f','');//字符0xc是表单提要
    Unicode引用有点棘手,因为它们是在Java解析器之前处理的,所以它们不能处理对Java语言有特殊意义的字符。但是使用表单提要,它是有效的

  • 使用正则表达式。对于此任务,这是一个规模过大的解决方案,但它的工作原理是执行单个字符的精确匹配是正则表达式语法的有效子集。因此,您可以使用上述所有变体,通过将方法名称替换为
    replaceAll
    ,并将参数更改为字符串,例如
    html=html.replaceAll(“\14”,”)
    在这种情况下,字符引用仍然由编译器生成,对正则表达式引擎没有特殊意义。
    当主动使用正则表达式引擎时,您可以选择与Java语言的字符引用类似的选项:

    • Unicode参考:
      html=html.replaceAll(“\\u000c”,”)
    • 十六进制引用:
      html=html.replaceAll(“\\x0c”,”);//没有Java等价物
    • 八进制引用:
      html=html.replaceAll(“\\014”,“”);//注意细微的差别
    • 根据其含义:
      html=html.replaceAll(“\\f”,即“)
  • 不同之处在于,这些序列在Java语言级别插入一个反斜杠(通过双反斜杠),形成一个由正则表达式引擎处理的正则表达式。因此,Unicode引用适用于此处的所有字符。 整个语法如下所述:

    但是,正如前面所说,对于您的任务,简单的字符匹配就足够了

    那么为什么你的例子不起作用呢

    html=html.replaceAll(“\000”和“)
    序列
    \0
    被解释为对控制字符0x0的引用,后跟两个零。因此,它试图找到控制字符
    NUL
    后跟两个零的序列

    html=html.replaceAll(“/\u000c+/g”,”)
    
    此序列由字符
    '/'
    '\f'
    (通过正确的unicode序列定义)
    '+'
    '/'
    'g'
    组成。在Java的正则表达式中,只有加号具有特殊意义。它的意思是“至少一个”和“尽可能多地找到”。因此,这段代码查找字符0xc的序列,但仅当它们被斜杠框住并后跟一个
    'g'

    时,它们都不是正确的Java代码。你说“我刚把它们放到我的html里”是什么意思。我指的是XML。。我只是使用html作为变量。那么,我应该怎么做才能转义xml中的所有unicode字符呢?