XML Feed中的字符非法? [英] Illegal character in XML feed?

查看:85
本文介绍了XML Feed中的字符非法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个Wordpress / WooCommerce插件,可以从我们的产品中创建XML文件。



但是在某些行中存在非法字符。

$ b第22栏第15622行的
$ b


 错误:输入不正确的UTF-8,指示编码! 
字节:0x03 0xC3 0xB6 0x73


我该如何解决此问题,以便正确解析XML?



XML数据文件



生成的代码如下:

  $ dom =新的DOMDocument('1.0','UTF-8'); 

//创建根元素
$ root = $ dom-> createElement( termeklista);
$ dom-> appendChild($ root);
$ dom-> formatOutput = true;

然后使用while循环填充数据。问题在描述标签中。

  //描述

$ description = $ dom-> ; createElement( leiras);
$ producta-> appendChild($ description);
//创建CDATA部分
$ cdata = $ dom-> createCDATASection( \n。$ loop-> post-> post_excerpt。 n);
$ description-> appendChild($ cdata);

我尝试使用iconv,utf8_encode,自定义函数来替换错误的字符,但我无法弄清楚是什么问题。



WooCommerce产品帖子摘录中没有任何非法字符。

解决方案

0x03 (又名 ^ C 又名 ETX aka 传输结束)不是 XML中允许的字符


  [2]字符:: =#x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] 


因此您的数据不是XML ,并且任何兼容的XML处理器都必须报告错误,例如收到的错误。



您必须通过将所有非法字符视为 <

I have created a Wordpress/WooCommerce plugin which creates an XML file from our products.

But in some rows there are illegal characters.

error on line 15622 at column 22: Input is not proper UTF-8, indicate encoding !
Bytes: 0x03 0xC3 0xB6 0x73

How can I solve this, so the XML is parsed correctly?

XML FEED FILE

The code for generating is something like:

$dom = new DOMDocument('1.0', 'UTF-8');

// create root element
$root = $dom->createElement("termeklista");
$dom->appendChild($root);
$dom->formatOutput=true;

then a while loop with filling the data. The issue is in the description tag.

// DESCRIPTION

$description = $dom->createElement("leiras");
$producta->appendChild($description);
// create CDATA section
$cdata = $dom->createCDATASection("\n".$loop->post->post_excerpt."\n");
$description->appendChild($cdata);

I have tried iconv, utf8_encode, custom function to replace the wrong characters, but I cannot figure it out what the issue.

The WooCommerce product post excerpt does not have any illegal characters in it.

解决方案

0x03 (aka ^C aka ETX aka end of transmission) is not an allowed character in XML :

[2] Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]

Therefore your data is not XML, and any conformant XML processor must report an error such as the one you received.

You must repair the data by removing any illegal characters by treating it as text, not XML, manually or automatically before using it with any XML libraries.

这篇关于XML Feed中的字符非法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆