XML child element



我在发布子元素到xml时遇到了问题。这是我的代码。如果我将来有许多静态组件要添加,我如何在xml中发布它们?

<TerminalStatusRequest>
    <TerminalID>AT0001</TerminalID>
    <ReaderID>SC0001</ReaderID>
    <ComponentName>Printer</ComponentName>
    <ComponentValue>Active</ComponentValue>
</TerminalStatusRequest>

您可以通过这种方式修复。您还可以在写入器对象

中添加多个节点。
 string path=@"c:\test.xml";
using (XmlWriter writer = XmlWriter.Create(path))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("TerminalStatusRequest");
                writer.WriteElementString("TerminalID","AT0001");
                writer.WriteElementString("ReaderID", "SC0001");
                writer.WriteElementString("ComponentName","Printer");
                writer.WriteElementString("ComponentValue","Active");
                writer.WriteEndElement();
                writer.WriteEndDocument();
            }

相关内容

最新更新