c#
  • asp.net
  • 2012-03-23 107 views 0 likes 
    0

    我有以下表行:非法XML字符

    <tr id="trInbox" runat="server" class="normal" 
        style='cursor:pointer; font-weight:<%# StyleBold(Convert.ToBoolean(Eval("inbRead"))) %>' 
        onclick='selectedRow(this,<%# Eval("INBID") %>)' 
        onMouseOver="if(this.className!='selected') this.style.backgroundColor='#E2E1F4';" 
        onMouseOut="if(this.className!='selected') this.style.backgroundColor='#FFFFFF'"> 
    

    但是,我跑这之后,我收到以下错误:

    illegal XML character [Break On This Error]

    selectedRow(this,<%# Eval("INBID") %>)

    你能告诉我,我缺少什么语法?

    +0

    什么是INBID'的'的价值,当你的错误? – Oded 2012-03-23 11:38:49

    回答

    1

    当运行元素服务器端时,最好在添加包含动态数据的属性值时使用String.Format()。请尝试:

    <tr id="trInbox" runat="server" class="normal" style='<%# String.Format("cursor:pointer; font-weight:{0}", StyleBold(Convert.ToBoolean(Eval("inbRead")))) %>' onclick='<%# String.Format("selectedRow(this,{0})", Eval("INBID")) %>' onMouseOver="if(this.className!='selected') this.style.backgroundColor='#E2E1F4';" onMouseOut="if(this.className!='selected') this.style.backgroundColor='#FFFFFF'"> 
    
    0

    也许您错过了“;”在onMouseOut上的backgroundColor风格。

    0

    我猜selectedRow方法做了一些涉及对象(反)序列化或将Xml字符串转换为Xml文档的处理。

    某些字符是非法的:http://www.w3.org/TR/REC-xml/#charsets

    您应该检查你的XML字符串,以消除任何无效字符。

    这里是实用方法的一个例子来检查字符是否有效:

    public static bool IsValidCharForXml(char x) 
        { 
         return x == (char)0x9 
            || x == (char)0xA 
            || x == (char)0xD 
            || (x >= (char)0x20 && x <= (char)0xD7FF) 
            || (x >= (char)0xE000 && x <= (char)0xFFFD); 
        } 
    
    相关问题