c#
  • asp.net
  • 2012-03-23 80 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); 
        } 
    
    相關問題