加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

XmlWriter将元素字符串写入属性

发布时间:2020-12-16 07:52:56 所属栏目:百科 来源:网络整理
导读:我正在使用XmlWriter,我想知道是否有人曾尝试使用属性来编写xml元素字符串(叶节点),以使输出看起来像 book id='1' author='j.k.rowling' year='2010'999/book 代替 book id='1' author='j.k.rowling' year='2010' book999/book/book 您可以使用 WriteString
我正在使用XmlWriter,我想知道是否有人曾尝试使用属性来编写xml元素字符串(叶节点),以使输出看起来像
<book id='1' author='j.k.rowling' year='2010'>999</book>

代替

<book id='1' author='j.k.rowling' year='2010'> 
    <book>999</book>
</book>
您可以使用 WriteString …
using (XmlWriter writer = XmlWriter.Create("books.xml"))
{

    writer.WriteStartElement("book"); 
    writer.WriteAttributeString("author","j.k.rowling"); 
    writer.WriteAttributeString("year","1990");
    writer.WriteString("99");
    writer.WriteEndElement();                                

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读