需要添加评论 [英] need to add comments

查看:62
本文介绍了需要添加评论的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在现有的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

谢谢大家


阅读有关该主题的以下内容:<?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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆