我写这样的代码
XmlDocument xdocMulticom = new XmlDocument();
StringWriter strwMultiXml = new StringWriter();
XmlTextWriter xmlMultiAirInfo = new XmlTextWriter(strwMultiXml);
xmlMultiAirInfo.Formatting = Formatting.None;
xmlMultiAirInfo.WriteStartDocument();
xmlMultiAirInfo.WriteStartElement("ns", "cancelreservation", "http://www.opentravel.org/ota/2003/05");
xmlMultiAirInfo.WriteStartElement("OTA_VehCancelRQ");
xmlMultiAirInfo.WriteAttributeString("xmlns", "http://www.opentravel.org/ota/2003/05");
xmlMultiAirInfo.WriteAttributeString("xmlns", "xsi", null, "http://www.w3.org/2001/XMLSchema-instance");
xmlMultiAirInfo.WriteAttributeString("Version", "1.002");
xmlMultiAirInfo.WriteAttributeString("PrimaryLangID", "EN");
xmlMultiAirInfo.WriteAttributeString("ReqRespVersion", "2.001");
xmlMultiAirInfo.WriteStartElement("POS");
xmlMultiAirInfo.WriteStartElement("Source");
xmlMultiAirInfo.WriteStartElement("RequestorID");
xmlMultiAirInfo.WriteAttributeString("Type", "4");
xmlMultiAirInfo.WriteAttributeString("ID", "F0F4CCE4A9C24355");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteStartElement("VehCancelRQCore");
xmlMultiAirInfo.WriteAttributeString("CancelType", "Cancel");
xmlMultiAirInfo.WriteStartElement("UniqueID");
xmlMultiAirInfo.WriteAttributeString("Type", "14");
xmlMultiAirInfo.WriteAttributeString("ID", "N2169641");
xmlMultiAirInfo.WriteStartElement("PersonName");
xmlMultiAirInfo.WriteElementString("GivenName", "Sandra");
xmlMultiAirInfo.WriteElementString("Surname", "Jhonsan");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteStartElement("VehCancelRQInfo");
xmlMultiAirInfo.WriteStartElement("Vendor");
xmlMultiAirInfo.WriteAttributeString("Code", "ZR");
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xmlMultiAirInfo.WriteEndElement();
xdocMulticom.LoadXml(strwMultiXml.ToString());
生成如下输出:
<?xml version="1.0" encoding="utf-16"?>
<ns:cancelreservation xmlns:ns="http://www.opentravel.org/ota/2003/05">
<OTA_VehCancelRQ xmlns="http://www.opentravel.org/ota/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.002" PrimaryLangID="EN" ReqRespVersion="2.001">
<POS>
<Source>
<RequestorID Type="4" ID="F0F4CCE4A9C24355" />
</Source>
</POS>
<VehCancelRQCore CancelType="Cancel">
<UniqueID Type="14" ID="N2169641">
<PersonName>
<GivenName>Sandra</GivenName>
<Surname>Jhonsan</Surname>
</PersonName>
</UniqueID>
</VehCancelRQCore>
<VehCancelRQInfo>
<Vendor Code="ZR" />
</VehCancelRQInfo>
</OTA_VehCancelRQ>
</ns:cancelreservation>
这对我来说没问题,但我需要它是这样的:
<?xml version="1.0" encoding="utf-16"?>
<ns:cancelreservation>
<OTA_VehCancelRQ xmlns="http://www.opentravel.org/ota/2003/05" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Version="1.002" PrimaryLangID="EN" ReqRespVersion="2.001">
<POS>
<Source>
<RequestorID Type="4" ID="F0F4CCE4A9C24355" />
</Source>
</POS>
<VehCancelRQCore CancelType="Cancel">
<UniqueID Type="14" ID="N2169641">
<PersonName>
<GivenName>Sandra</GivenName>
<Surname>Jhonsan</Surname>
</PersonName>
</UniqueID>
</VehCancelRQCore>
<VehCancelRQInfo>
<Vendor Code="ZR" />
</VehCancelRQInfo>
</OTA_VehCancelRQ>
</ns:cancelreservation>
有没有办法改变它?