解析无效的XML C#

时间:2017-04-12 00:08:46

标签: c# xml parsing serialization

这是我需要用C#解析的无效xml响应, 我试图为答案创建一个课程并且收效甚微。

<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>

1 个答案:

答案 0 :(得分:3)

听起来您正在尝试使用标准C#XML库来解析非合法的XML文件。

那不行。您需要先将文件设置为“有效”。

建议:

  1. 将XML文本读入字符串。

  2. 将所有\"替换为"

  3. 使用标准库来解析“已更正的”XML。