I am currently developing some solution based on communication through httpwebrequest between some distant (Prestashop) MYSQL database and return on information.
The concept is working like a charm, and I use to load some object, like customers, groups or products through a build Xml response, I de-serialized. All object return same kind of process and all are loading perfectly. But in case of the products, I recently faced a mysterious bug, saying that my xml contains several root element, witch is completely wrong. I feel very at ease with Xml building, so I became crazy not finding a way out. The c# function who operate de serialization is quite simple :
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;
}
To illustrate It, here is a first example loading a group who is working perfectly :
<?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>
But when I load a Object type product :
<?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>
I get with this products and all other a System.Xml.XmlException: 'They are several root element. Line 2, position 2.'
There is only one root element : "object", and each nodes are unique, I have been trying to all online Xml checker, my return Xml pass every test successfully,so I just turn a little crazy.
So if there are some good soul who would maybe give me a suggestion, or a beginning of explanation, or simply point to my attention a huge mistake I am doing, I would highly appreciate It :)
Million of thanks in advance !
Jeff
So the mistake went from linux Server side due to ** @ini_set('display_errors', 'on');
**
Everything is rolling great again !
Thanks for all your concerns and support !
Jeff