双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

xml输出无子节点带结束符的问题

superall superall 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
请问有哪位知道,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>
...全文
评论
收藏 已收藏
分享
返回顶部
superall
C# 111,129 成员 642,540 内容