Я создаю XML в C #. Однако я столкнулся с трудностями при добавлении пробела перед значением атрибута.
XmlWriterSettings SettingWritterXML = new XmlWriterSettings();
SettingWritterXML.Indent = true;
SettingWritterXML.ConformanceLevel = ConformanceLevel.Document;
SettingWritterXML.NewLineOnAttributes = false;
XmlWriter objXmlWriter = XmlWriter.Create(@output_file_path + path + ".xml", SettingWritterXML);
objXmlWriter.WriteStartDocument();
objXmlWriter.WriteStartElement("Bin");
objXmlWriter.WriteString(Environment.NewLine);
objXmlWriter.WriteStartElement("Bin");
objXmlWriter.WriteAttributeString("BinCode", "001");
objXmlWriter.WriteAttributeString("BinCount", tot_pass.ToString());
objXmlWriter.WriteAttributeString("BinQuality", "Pass");
objXmlWriter.WriteEndElement();
objXmlWriter.WriteString(Environment.NewLine);
objXmlWriter.WriteStartElement("Bin");
objXmlWriter.WriteAttributeString("BinCode", "040");
objXmlWriter.WriteAttributeString("BinCount", tot_fail.ToString());
objXmlWriter.WriteAttributeString("BinQuality", "Fail");
objXmlWriter.WriteEndElement();
objXmlWriter.WriteString(Environment.NewLine);
objXmlWriter.WriteStartElement("Bin");
objXmlWriter.WriteAttributeString("BinCode", "099");
objXmlWriter.WriteAttributeString("BinCount", tot_skip.ToString());
objXmlWriter.WriteAttributeString("BinQuality", "Null");
objXmlWriter.WriteEndElement();
objXmlWriter.WriteString(Environment.NewLine);
objXmlWriter.WriteEndElement();
objXmlWriter.WriteString(Environment.NewLine);
Фактический результат:
<?xml version="1.0" encoding="utf-8"?>
<Bin>
<Bin BinCode="001" BinCount="1465" BinQuality="Pass" />
<Bin BinCode="040" BinCount="1231" BinQuality="Fail" />
<Bin BinCode="099" BinCount="113" BinQuality="Null" />
</Bin>
Ожидаемый результат:
<?xml version="1.0" encoding="utf-8"?>
<Bin>
<Bin BinCode= "001" BinCount= "1465" BinQuality= "Pass" />
<Bin BinCode= "040" BinCount= "1231" BinQuality= "Fail" />
<Bin BinCode= "099" BinCount= "113" BinQuality= "Null" />
</Bin>
* Там, где после атрибута "=" в атрибуте есть пробел.