在我的 xml 中正确级别保存新元素时出现问题
我有一个如下所示的 xml 文件:
<DataTalk>
<Posts>
<TalkPost>
<PostType>dialog</PostType>
<User>ABBE</User>
<Customer>HRM - Heroma</Customer>
<PostedDate>0001-01-01T00:00:00</PostedDate>
<Message>TEST</Message>
</TalkPost>
</Posts>
</DataTalk>
当我现在想要保存新元素时,我会这样做:
document.root.add((new XElement("TalkPost", new XElement("PostType", newDialog.PostType),
new XElement("User", newDialog.User), new XElement("Customer", newDialog.Customer),
new XElement("PostedDate", newDialog.PostDate), new XElement("Message", newDialog.Message)));
现在的问题是它保存在错误的层次结构级别。它们都保存在
下,而不是我不想保存的
下。我应该如何将新元素分层保存在
下
I have a xml file that looks like this:
<DataTalk>
<Posts>
<TalkPost>
<PostType>dialog</PostType>
<User>ABBE</User>
<Customer>HRM - Heroma</Customer>
<PostedDate>0001-01-01T00:00:00</PostedDate>
<Message>TEST</Message>
</TalkPost>
</Posts>
</DataTalk>
When I now want to save new elements, I do:
document.root.add((new XElement("TalkPost", new XElement("PostType", newDialog.PostType),
new XElement("User", newDialog.User), new XElement("Customer", newDialog.Customer),
new XElement("PostedDate", newDialog.PostDate), new XElement("Message", newDialog.Message)));
The problem is now that it gets saved at the wrong hierarchal level. They all gets saved under <datatalk>
and not under <posts>
that I wan't to. How should I do to save the new elements under the <posts>
hierarchically
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
document.Root.Element("Posts").Add(new XElement("TalkPost", ...));
应该可以。document.Root.Element("Posts").Add(new XElement("TalkPost", ...));
should do.