c# LoadXml randomly return 它们是几个根元素,没有任何明显的原因
c# LoadXml randomly return they are several root element without any obvious reasons
我目前正在开发一些基于远程 (Prestashop) MYSQL 数据库和 return 信息之间的 httpwebrequest 通信的解决方案。
这个概念就像一个魅力,我用来通过构建 Xml 响应加载一些对象,如客户、组或产品,我反序列化。所有对象 return 都是同一种进程,并且都在完美加载。
但是在产品的情况下,我最近遇到了一个神秘的错误,说我的 xml 包含几个根元素, 是完全错误的。我对Xml建筑很放心,所以我疯了找不到出路。
反序列化的c#函数很简单:
public static Dictionary<string, string> get(IRestResponse response)
{
var objectToLoad = new Dictionary<string, string>();
XmlDocument doc = new XmlDocument();
doc.LoadXml(response.Content.ToString());
XmlNodeList idNodes = doc.SelectNodes("object");
foreach (XmlNode node1 in idNodes)
{
foreach (XmlNode node in node1.ChildNodes)
{
objectToLoad.Add(node.Name, node.InnerText);
}
}
return objectToLoad;
}
为了说明它,这里是第一个加载工作完美的组的示例:
<?xml version="1.0" encoding="UTF-8"?>
<object>
<id>4</id>
<reduction>0</reduction>
<price_display_method>0</price_display_method>
<show_prices>1</show_prices>
<date_add>2014-09-23 16:23:05</date_add>
<date_upd>2014-10-14 09:27:09</date_upd>
<name>Public VIP</name>
<id_lang>1</id_lang>
</object>
但是当我加载对象类型产品时:
<?xml version="1.0" encoding="UTF-8"?>
<object>
<id>6</id>
<id_shop_default>1</id_shop_default>
<id_manufacturer>1</id_manufacturer>
<id_supplier>1</id_supplier>
<reference>MTDENIMJR</reference>
<supplier_reference></supplier_reference>
<location></location>
<width>0</width>
<height>0</height>
<depth>0</depth>
<weight>0.05</weight>
<quantity_discount>0</quantity_discount>
<ean13>815264500995</ean13>
<upc>815264500995</upc>
<cache_is_pack>0</cache_is_pack>
<cache_has_attachments>0</cache_has_attachments>
<is_virtual>0</is_virtual>
<id_category_default>9</id_category_default>
<id_tax_rules_group>1</id_tax_rules_group>
<on_sale>1</on_sale>
<online_only>0</online_only>
<ecotax>0</ecotax>
<minimal_quantity>1</minimal_quantity>
<price>10.313</price>
<wholesale_price>2.9</wholesale_price>
<unity></unity>
<unit_price_ratio>0</unit_price_ratio>
<additional_shipping_cost>0</additional_shipping_cost>
<customizable>0</customizable>
<text_fields>0</text_fields>
<uploadable_files>0</uploadable_files>
<active>1</active>
<redirect_type>404</redirect_type>
<id_product_redirected>0</id_product_redirected>
<available_for_order>1</available_for_order>
<available_date>0000-00-00</available_date>
<condition>new</condition>
<show_price>1</show_price>
<indexed>1</indexed>
<visibility>both</visibility>
<cache_default_attribute>0</cache_default_attribute>
<advanced_stock_management>0</advanced_stock_management>
<date_add>2013-02-27 08:03:35</date_add>
<date_upd>2018-05-09 10:59:40</date_upd>
<pack_stock_type>3</pack_stock_type>
<groups_allowed></groups_allowed>
<flashsale>0</flashsale>
<id_google_category>36</id_google_category>
<meta_description>Vernis à Ongle Morgan Taylor Denim Du Jour Format 15 ml</meta_description>
<meta_keywords>vernis à ongles,morgantaylor,manucure,beauté des mains,nails,harmony</meta_keywords>
<meta_title></meta_title>
<link_rewrite>morgan-taylor-denim-du-jour</link_rewrite>
<name>Morgan Taylor Denim Du Jour</name>
<description><p>Vernis à Ongle Morgan Taylor Denim Du Jour 15 ml</p></description>
<description_short></description_short>
<available_now></available_now>
<available_later></available_later>
<id_lang>1</id_lang>
<id_shop>1</id_shop>
</object>
我得到了这个产品和所有其他产品System.Xml.XmlException:'They are several root element. Line 2, position 2.'
只有一个根元素:"object",而且每个节点都是唯一的,我一直在尝试所有在线Xml检查器,我的return Xml通过每次测试都成功,所以我有点疯狂。
因此,如果有好心人可能会给我一个建议,或者开始解释,或者只是指出我正在犯的一个巨大错误,我将不胜感激:)
万分感谢!
杰夫
所以错误来自 linux 服务器端,原因是 ** @ini_set('display_errors', 'on');
**
一切又开始了!
感谢大家的关心和支持!
杰夫
我目前正在开发一些基于远程 (Prestashop) MYSQL 数据库和 return 信息之间的 httpwebrequest 通信的解决方案。
这个概念就像一个魅力,我用来通过构建 Xml 响应加载一些对象,如客户、组或产品,我反序列化。所有对象 return 都是同一种进程,并且都在完美加载。 但是在产品的情况下,我最近遇到了一个神秘的错误,说我的 xml 包含几个根元素, 是完全错误的。我对Xml建筑很放心,所以我疯了找不到出路。 反序列化的c#函数很简单:
public static Dictionary<string, string> get(IRestResponse response)
{
var objectToLoad = new Dictionary<string, string>();
XmlDocument doc = new XmlDocument();
doc.LoadXml(response.Content.ToString());
XmlNodeList idNodes = doc.SelectNodes("object");
foreach (XmlNode node1 in idNodes)
{
foreach (XmlNode node in node1.ChildNodes)
{
objectToLoad.Add(node.Name, node.InnerText);
}
}
return objectToLoad;
}
为了说明它,这里是第一个加载工作完美的组的示例:
<?xml version="1.0" encoding="UTF-8"?>
<object>
<id>4</id>
<reduction>0</reduction>
<price_display_method>0</price_display_method>
<show_prices>1</show_prices>
<date_add>2014-09-23 16:23:05</date_add>
<date_upd>2014-10-14 09:27:09</date_upd>
<name>Public VIP</name>
<id_lang>1</id_lang>
</object>
但是当我加载对象类型产品时:
<?xml version="1.0" encoding="UTF-8"?>
<object>
<id>6</id>
<id_shop_default>1</id_shop_default>
<id_manufacturer>1</id_manufacturer>
<id_supplier>1</id_supplier>
<reference>MTDENIMJR</reference>
<supplier_reference></supplier_reference>
<location></location>
<width>0</width>
<height>0</height>
<depth>0</depth>
<weight>0.05</weight>
<quantity_discount>0</quantity_discount>
<ean13>815264500995</ean13>
<upc>815264500995</upc>
<cache_is_pack>0</cache_is_pack>
<cache_has_attachments>0</cache_has_attachments>
<is_virtual>0</is_virtual>
<id_category_default>9</id_category_default>
<id_tax_rules_group>1</id_tax_rules_group>
<on_sale>1</on_sale>
<online_only>0</online_only>
<ecotax>0</ecotax>
<minimal_quantity>1</minimal_quantity>
<price>10.313</price>
<wholesale_price>2.9</wholesale_price>
<unity></unity>
<unit_price_ratio>0</unit_price_ratio>
<additional_shipping_cost>0</additional_shipping_cost>
<customizable>0</customizable>
<text_fields>0</text_fields>
<uploadable_files>0</uploadable_files>
<active>1</active>
<redirect_type>404</redirect_type>
<id_product_redirected>0</id_product_redirected>
<available_for_order>1</available_for_order>
<available_date>0000-00-00</available_date>
<condition>new</condition>
<show_price>1</show_price>
<indexed>1</indexed>
<visibility>both</visibility>
<cache_default_attribute>0</cache_default_attribute>
<advanced_stock_management>0</advanced_stock_management>
<date_add>2013-02-27 08:03:35</date_add>
<date_upd>2018-05-09 10:59:40</date_upd>
<pack_stock_type>3</pack_stock_type>
<groups_allowed></groups_allowed>
<flashsale>0</flashsale>
<id_google_category>36</id_google_category>
<meta_description>Vernis à Ongle Morgan Taylor Denim Du Jour Format 15 ml</meta_description>
<meta_keywords>vernis à ongles,morgantaylor,manucure,beauté des mains,nails,harmony</meta_keywords>
<meta_title></meta_title>
<link_rewrite>morgan-taylor-denim-du-jour</link_rewrite>
<name>Morgan Taylor Denim Du Jour</name>
<description><p>Vernis à Ongle Morgan Taylor Denim Du Jour 15 ml</p></description>
<description_short></description_short>
<available_now></available_now>
<available_later></available_later>
<id_lang>1</id_lang>
<id_shop>1</id_shop>
</object>
我得到了这个产品和所有其他产品System.Xml.XmlException:'They are several root element. Line 2, position 2.'
只有一个根元素:"object",而且每个节点都是唯一的,我一直在尝试所有在线Xml检查器,我的return Xml通过每次测试都成功,所以我有点疯狂。
因此,如果有好心人可能会给我一个建议,或者开始解释,或者只是指出我正在犯的一个巨大错误,我将不胜感激:)
万分感谢!
杰夫
所以错误来自 linux 服务器端,原因是 ** @ini_set('display_errors', 'on');
**
一切又开始了!
感谢大家的关心和支持!
杰夫