我有一个菜单,我通过以下方式绑定数据:
XmlDataSource xmlData = new XmlDataSource();
xmlData.DataFile = String.Format(@"{0}{1}\Navigation.xml", getXmlPath(), getLanguage());
xmlData.XPath = @"/Items/Item";
TopNavigation.DataSource = xmlData;
TopNavigation.DataBind();
问题是当我的 xml 有特殊字符时,因为我使用了很多法语单词。
作为替代方案,我尝试使用流代替并使用编码来获取特殊字符,代码如下:
StreamReader strm = new StreamReader(String.Format(@"{0}{1}\Navigation.xml", getXmlPath(), getLanguage()), Encoding.GetEncoding(1254));
XmlDocument xDoc = new XmlDocument();
xDoc.Load(strm);
XmlDataSource xmlData = new XmlDataSource();
xmlData.ID = "TopNav";
xmlData.Data = xDoc.InnerXml;
xmlData.XPath = @"/Items/Item";
TopNavigation.Items.Clear();
TopNavigation.DataSource = xmlData;
TopNavigation.DataBind();
我现在遇到的问题是,当我更改读取流的路径时,我的数据不会刷新。
当我跳过代码时,它会跳过,但不在我的页面上。
所以问题是,我如何刷新数据?或者(实际上是首选)如何在第一段代码中正确编码?
非常感谢您的帮助!
编辑:
我尝试了 CDATA 解决方案,但是我正在使用属性,因此无法在属性中指定元素,我的 xml:
<?xml version="1.0" encoding="utf-8" ?>
<Items Text="">
<Item Text="Actualités>"/>
<Item Text="Matériau">
<Item Text="Arsenal"/>
<Item Text="Vêtements"/>
</Item>
<Item Text="Links"/>
</Items>
还有其他想法吗?