2017-04-12 111 views
2

這是我需要用C#解析的無效xml響應, 我正在嘗試爲響應創建一個類,並且收效甚微。解析無效的XML C#

<Response service=\"RouteService\"> 
<Head>OK</Head> 
<Body> 
    <RouteResponse mailno=\"070033764942\"> 
     <Route accept_time=\"2017-03-23 10:57:13\"\taccept_address=\"United States\"\tremark=\"For Sign Info, please see 'AWB Info &amp; POD' in our website\"\topcode=\"8000\"/> 
     <Route accept_time=\"2017-03-23 10:52:10\"\taccept_address=\"United States\"\tremark=\"Have been signed(MS.TT),Thank you for using SF, and looking forward to serving you again\"\topcode=\"80\"/> 
     <Route accept_time=\"2017-03-23 10:52:10\"\taccept_address=\"United States\"\tremark=\"Have been signed(MS.TT),Thank you for using SF, and looking forward to serving you again\"\topcode=\"80\"/> 
     <Route accept_time=\"2017-03-23 10:46:37\"\taccept_address=\"SHENZHEN CITY\"\tremark=\"S.F. Express has picked up the shipment\"\topcode=\"50\"/> 
     <Route accept_time=\"2017-03-23 10:46:37\"\taccept_address=\"SHENZHEN CITY\"\tremark=\"S.F. Express has picked up the shipment\"\topcode=\"50\"/> 
    </RouteResponse> 
</Body> 

+3

用'''用'''全部替換'\'''用''替換全部'\ t'? – DavidG

+0

修復生成無效xml的代碼。 – jdweng

回答

3

這聽起來像你想使用標準的C#XML庫來解析非法律的XML文件。

這是行不通的。您需要先使文件「有效」。

建議:

  1. 讀取XML文本轉換成字符串。

  2. 全部替換\""

  3. 使用標準庫來解析「更正」的XML。

+1

確實需要在\ t中添加空格,以便進行正確的解析。 –