xml输出无子节点带结束符的问题
请问有哪位知道,xml输出时想给没有字节点的node输出结束符如何处理?XmlNode Switch = doc.CreateElement("Switch");
XmlAttribute swID = doc.CreateAttribute("Id");
swID.Value = ats_switch[i].Switchid;
Switch.Attributes.Append(swID);
XmlAttribute swName = doc.CreateAttribute("Name");
string name = ats_switch[i].switchname;
swName.Value = name.Substring(1, name.Length - 1);
Switch.Attributes.Append(swName);
XmlAttribute swNameid = doc.CreateAttribute("NameId");
swNameid.Value = name.Substring(1, name.Length - 1);
Switch.Attributes.Append(swNameid);
XmlAttribute Zone = doc.CreateAttribute("Zone");
string zoneid = "xpath(//Zone[@Id='" + ats_switch[i].zone + "'])";
Zone.Value = zoneid;
Switch.Attributes.Append(Zone);
Elements.AppendChild(Switch);
以上代码输出的是如下:
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])"/>
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])"/>
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])"/>
我要输出的是:
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])">
</Switch>
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])">
</Switch>
<Switch Id="4" Name="6" NameId="6" Zone="xpath(//Zone[@Id='2172'])">
</Switch>
补充:.NET技术 , C#