2010-05-06 51 views
1

大家好我是通過解析器閱讀XMLDATA

我收到錯誤,如讀取數據作爲xmlElemet ..「\ B」,十六進制值0x08時,是無效字符

我讀這個字符串.. 謝謝..

 XElement xParser = null; 
      string sPwd = null; 
      string sKey1 = null; 
      string sKey2 = null; 
      System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding(); 
      string soutxml = ""; 

      soutxml = encoding.GetString(sEncData); 
      xParser = XElement.Parse(soutxml); 

     IEnumerable<XElement> elemsValidations = 
       from el in xParser.Elements("EmailPwd") 
      select el; 

     foreach (XElement elemValidation in elemsValidations) 
     { 
      sPwd = elemValidation.Element("EncPwd").Value; 
      sKey1 = elemValidation.Element("Key1").Value; 
      sKey2 = elemValidation.Element("Key2").Value; 
     } 

      byte[] Key1 = encoding.GetBytes(sKey1); 
      byte[] Key2 = encoding.GetBytes(sKey2); 
      byte[] Data = encoding.GetBytes(sPwd); 

      // Decrypt the buffer back to a string. 
      string Final = DecryptTextFromMemory(Data, Key1, Key2); 

      return Final; 

該數據是實際的數據輸出..

- <EmailPwd> 
- <EncPwd> 
- <![CDATA[ [email protected]]Z 
    ]]> 
    </EncPwd> 
- <Key1> 
- <![CDATA[ ~??s????E&?3??2?3I????? 
    ]]> 
    </Key1> 
- <Key2> 
- <![CDATA[ ???h?6 
    ]]> 
    </Key2> 
    </EmailPwd> 
+0

哪裏是字符串?你使用哪個解析器?任何代碼示例? – Kangkan 2010-05-06 05:29:14

+0

我會送你一些前。我讀這個數據只是看我的代碼 – 2010-05-06 06:26:10

回答

1

您的數據似乎在其中包含一個char 0x08。根據XML specification,這不是有效的XML,所以解析器在提出錯誤時是正確的

您必須將數據更改爲有效的XML - 通過更改無效字符。並且/或者要求數據的提供者提供他們目前沒有做的XML。