【发布时间】:2011-01-22 09:52:43
【问题描述】:
在我的 XML 中,撇号可能出现在节点的值中:
<Root>
<Sections>
<SectionA>
<Heading>Title</Heading>
<Description>This is section 'A'</Description>
</SectionA>
</Sections>
</Root>
如果我有绑定到这个 XML 的控件:
<asp:FormView ID="myFormView" runat="server" DataSourceID="myXmlDataSource">
<ItemTemplate>
<div>
HTML Element:
<input type="text" value='<%# XPath("text()") %>' />
</div>
<div>
Server Control:
<asp:TextBox id="myTextBox" runat="server" value='<%# XPath("text()") %>' />
</div>
</ItemTemplate>
</asp:FormView>
<asp:XmlDataSource ID="myXmlDataSource" runat="server" XPath="Root/Sections/SectionA" />
我注意到文本在 asp:TextBox 中正确显示,但在 INPUT 元素中没有。我假设这是因为服务器控件正确地转义了撇号。为了解决这个问题,我尝试将 XML 中的描述节点更改为以下内容:
<Description>This is section 'A'</Description>
同样,它在 asp:TextBox 中正确显示,但在 INPUT 元素中却没有。
我的下一个尝试是将节点的值包装在 CDATA 中:
<Description><![CDATA[This is section 'A']]></Description>
最后它在 INPUT 元素中正确显示,但现在 asp:TextBox 显示了两个“ 9;”。我什至试过“& a p o s ;”但结果是一样的。
在可以在服务器控件或 HTML 元素中显示值的 XML 中使用撇号的最佳方法是什么?
【问题讨论】:
标签: asp.net html xml data-binding