删除缺少的关闭选项标签

时间:2012-04-13 15:05:22

标签: c# asp.net .net sitecore

我有一个下拉列表,但缺少结束选项标记。这会导致站点无法针对XHTML 1.1进行W3C验证

这是我的HTML:

<select>
    <option value="">Select...
    <option value="val1">Value One
    <option value="val2">Value Two
</select>

我希望如此:

<select>
    <option value="">Select...</option>
    <option value="val1">Value One</option>
    <option value="val2">Value Two</option>
</select>

我尝试了HtmlSelectDropDownList。我尝试添加ListItem和数据绑定以填充它,但我每次都得到相同的HTML。

知道可能导致这种情况的原因吗?

修改

我使用的是.NET 3.5,该网站是Sitecore网站。

这是我的doctype声明:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

像这样填充:

HtmlSelect dropdown = new HtmlSelect();
dropdown.ID = _Data.ControlID;

List<DataCollectionItem> lisItemCollection = new List<DataCollectionItem>();

foreach (DataCollectionItem item in lisItemCollection)
    dropdown.Items.Add(new ListItem(item.Text, item.Value));

也试过这个,结果相同:

dropdown.DataSource = lisItemCollection;
dropdown.DataTextField = "Text";
dropdown.DataValueField = "Value";
dropdown.DataBind();

浏览器文件:

Form.browser

<browsers>
  <browser refID="Default">
    <controlAdapters>
      <adapter controlType="System.Web.UI.HtmlControls.HtmlForm" adapterType="Sitecore.Web.FormAdapter, Sitecore.Kernel" />
    </controlAdapters>
  </browser>
</browsers>

w3cValidator.browser

<browsers> 
  <!--  Browser capability file for the w3c validator 
        sample UA: "W3C_Validator/1.305.2.148 libwww-perl/5.803" 
  --> 
  <browser id="w3cValidator" parentID="default"> 
    <identification> 
      <userAgent match="^W3C_Validator" /> 
    </identification> 

    <capture> 
      <userAgent match="^W3C_Validator/(?'version'(?'major'\d+)(?'minor'\.\d+)\w*).*" /> 
    </capture> 

    <capabilities> 
      <capability name="browser" value="w3cValidator" /> 
      <capability name="majorversion" value="${major}" /> 
      <capability name="minorversion" value="${minor}" /> 
      <capability name="version" value="${version}" /> 
      <capability name="w3cdomversion" value="1.0" /> 
      <capability name="xml" value="true" /> 
      <capability name="tagWriter" value="System.Web.UI.HtmlTextWriter" /> 
    </capabilities> 
  </browser> 
</browsers>

1 个答案:

答案 0 :(得分:0)

事实证明问题是由于HTML Agility包。

HtmlNode.ElementsFlags.Remove("option");

有关详细信息,请参阅this question