外在因素结束标记与System.Xml.Linq的命名空间 [英] Explicit Element Closing Tags with System.Xml.Linq Namespace

查看:116
本文介绍了外在因素结束标记与System.Xml.Linq的命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的(.NET 3.5 SP1)System.Xml.Linq的命名空间来使用数据填充的div标签的HTML模板文档(然后将其保存到磁盘)。有时div标签是空的,这似乎是当它涉及到HTML是一个问题。根据我的研究,DIV标签是不是自闭。因此,Firefox的下至少一个< D​​IV /方式> 被认为是不匹配的结束标记开口div标签

I am using the (.NET 3.5 SP1) System.Xml.Linq namespace to populate an html template document with div tags of data (and then save it to disk). Sometimes the div tags are empty and this seems to be a problem when it comes to HTML. According to my research, the DIV tag is not self-closing. Therefore, under Firefox at least, a <div /> is considered an opening div tag without a matching closing tag.

所以,当我通过声明创建新的div元素:

So, when I create new div elements by declaring:

XElement divTag = new XElement("div");



如何可以强制生成的XML是< D​​IV> ;< / DIV> 而不是< D​​IV />

How can I force the generated XML to be <div></div> instead of <div /> ?

推荐答案

我不知道为什么你会用一个空的DIV结束了(好像有点毫无意义!)但是:

I'm not sure why you'd end up with an empty DIV (seems a bit pointless!) But:

divTag.SetValue(string.Empty);



应该这样做。

Should do it.

这篇关于外在因素结束标记与System.Xml.Linq的命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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