潇湘沐
我通过使用 XMLwriter 创建 xml 字符串来修复它,以下是代码的结束方式:$xw = xmlwriter_open_memory();xmlwriter_set_indent($xw, 1);$res = xmlwriter_set_indent_string($xw, ' ');xmlwriter_start_document($w, '1.0', 'UTF-8');xmlwriter_start_element($xw, 'PriceFeed');xmlwriter_start_attribute($xw, 'xmlns');xmlwriter_text($xw, 'http://walmart.com/');xmlwriter_end_attribute($xw);xmlwriter_start_element($xw, 'PriceHeader');xmlwriter_start_element($xw, 'version');xmlwriter_text($xw, '1.5.1');xmlwriter_end_element($xw);xmlwriter_end_element($xw);foreach($sorted_data as $data){ xmlwriter_start_element($xw, 'Price'); xmlwriter_start_element($xw, 'itemIdentifier'); xmlwriter_start_element($xw, 'sku'); xmlwriter_text($xw, $data["SKU"]); xmlwriter_end_element($xw); xmlwriter_end_element($xw); xmlwriter_start_element($xw, 'pricingList'); xmlwriter_start_element($xw, 'pricing'); xmlwriter_start_element($xw, 'currentPrice'); xmlwriter_start_element($xw, 'value'); xmlwriter_start_attribute($xw, 'currency'); xmlwriter_text($xw, 'USD'); xmlwriter_start_attribute($xw, 'amount'); xmlwriter_text($xw, $data['Price']); xmlwriter_end_attribute($xw); xmlwriter_end_element($xw); xmlwriter_end_element($xw); xmlwriter_end_element($xw); xmlwriter_end_element($xw); xmlwriter_end_element($xw); xmlwriter_end_element($xw);}xmlwriter_end_document($xw);echo xmlwriter_output_memory($xw);