需要添加评论 [英] need to add comments
本文介绍了需要添加评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要在现有的xml文档中添加注释.下面显示了一个示例xml,我需要用c#编写代码. XML序列化用于生成此xml
任何帮助都会很棒...
在此先感谢
<? xml 版本 =" 编码 =" utf-8" >
< 人员 >
< 名称 > hi < /名称 >
< 地址 > 10dcalp < /地址 >
< 年龄 > 12 < /年龄 >
< /人 > pre> 解决方案
foreach (XElement项目 doc.Descendants(" )中)
{
XElement ObjElement = item .Element(" );
XComment comm = 新 XComment(" );
xe1.AddBeforeSelf(comm);
}
遍历根节点并转到您的元素.通过使用XElement''S object.AddBeforeSelf()方法,我们可以添加注释.并保存XDocument
谢谢大家
阅读有关该主题的以下内容: ^ ]
I need to add comments in an existing xml document.a sample xml is shown below i need to write code in c#. XML serialization was used to generate this xml
any help would be great...
thanks in advance
<?xml version="1.0" encoding="utf-8"?>
<Person>
<Name>hi</Name>
<Address>10dcalp</Address>
<Age>12</Age>
</Person>
解决方案 foreach (XElement item in doc.Descendants("NodeName"))
{
XElement ObjElement= item .Element("ElementName");
XComment comm = new XComment("Add Comment Here");
xe1.AddBeforeSelf(comm);
}
Iterate through the root nodes and go to your element. By using XElement''S object.AddBeforeSelf() method we can add our comments. and save the XDocument
Thank you all
Read the following on the subject : http://stackoverflow.com/questions/2129414/how-to-insert-xml-comments-in-xml-serialization[^]
这篇关于需要添加评论的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文