我的DOMParser在读取xml时抛出此异常
[Fatal Error] .... The markup in the document following the root element must be well-formed.
我的XML是:
<?xml version="1.0" encoding="UTF-8"?>
<PacketDetails>
<RefrenceNumber>SLP264531195</RefrenceNumber>
<AwbNumber>83047273</AwbNumber>
<ShipperAccountNumber>Cus092</ShipperAccountNumber>
<ConsigneeAddress>1.0,835210</ConsigneeAddress>
<ConsigneePhone>1</ConsigneePhone>
<StatusChanges>
<Status>
<StatusId>1</StatusId>
<StatusName>Return to Origin - Delivered</StatusName>
<city>Delhi</city>
<UpdateDate>2015-04-04</UpdateDate>
</Status>
<Status>
<StatusId>3</StatusId>
<StatusName>Return to Origin - Received</StatusName>
<city>Delhi</city>
<UpdateDate>2015-04-04</UpdateDate>
</Status>
<Status>
<StatusId>1</StatusId>
<StatusName>Return to Origin - In transit</StatusName>
<city>Delhi</city>
<UpdateDate>2015-03-28</UpdateDate>
</Status>
<Status>
<StatusId>1</StatusId>
<StatusName>Return to Origin - In transit</StatusName>
<city>Delhi</city>
<UpdateDate>2015-03-12</UpdateDate>
</Status>
<Status>
<StatusId>2</StatusId>
<StatusName>Packet - out of delivery area</StatusName>
<city>Ranchi</city>
<UpdateDate>2015-03-10</UpdateDate>
</Status>
<Status>
<StatusId>2</StatusId>
<StatusName>Packet - out of delivery area</StatusName>
<city>Ranchi</city>
<UpdateDate>2015-03-07</UpdateDate>
</Status>
<Status>
<StatusId>4</StatusId>
<StatusName>Out for delivery</StatusName>
<city>Ranchi</city>
<UpdateDate>2015-03-07</UpdateDate>
</Status>
<Status>
<StatusId>8</StatusId>
<StatusName>Packet Received At Operation Facility</StatusName>
<city>Ranchi</city>
<UpdateDate>2015-03-07</UpdateDate>
</Status>
<Status>
<StatusName>In Transit</StatusName>
<city>Patna</city>
<UpdateDate>2015-03-07</UpdateDate>
</Status>
<Status>
<StatusId>9</StatusId>
<StatusName>Packet Forwarded To Destination</StatusName>
<city>Jharkhand</city>
<UpdateDate>2015-03-03</UpdateDate>
</Status>
<Status>
<StatusId>8</StatusId>
<StatusName>Packet Received At Operation Facility</StatusName>
<city>Gurgaon</city>
<UpdateDate>2015-03-02</UpdateDate>
</Status>
</StatusChanges>
</PacketDetails>
我在论坛上看到了其他Q,但在我看来xml看起来不错。请指出我正确的方向。
编辑:xml来自网址。我现在已经粘贴了完整的xml,但它看起来还不错。
答案 0 :(得分:2)
您展示的XML很好。
问题在于您没有显示的XML。错误消息表明存在第二个根元素,well-formed XML中不允许这样做。
更新
您展示的新XML也很好。
正如Michael Kay在评论中提到的,这不是解析器所看到的XML。 您必须找到解析器实际看到的XML才能解决您的问题:
尝试在解析之前立即将提供的XML转储到解析器,这样您就可以确定您正在查看解析器正在读取的内容。虽然在我见过的大多数解析器中并不常见/可能,但是在先前的运行之后解析器没有被正确初始化或重置,这也是可以想象的。真的,专注于找到解析器真正看到的东西来磨练你的问题。