0

My DOMParser is throwing this exception when reading the xml

[Fatal Error] .... The markup in the document following the root element must be well-formed.

My XML is:

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

I saw the other Qs on the forum, but it seems to me that the xml looks good. Please point me in the right direction.

Edit : xml comes from a URL. I have pasted the complete xml now, but it looks ok to me.

rajya vardhan
  • 1,121
  • 4
  • 16
  • 29
  • 1
    Nothing wrong with xml. Where does the xml come from, a file or a http request. I would check to see if there additional unprintable characters that are not seen in the xml stream. – faljbour Apr 09 '15 at 01:07

1 Answers1

2

The XML you've shown is fine.

The problem lies with the XML you've not shown. The error message indicates that there's a second root element, which is not allowed in well-formed XML.


Update after more XML posted

The new XML you've shown is also fine.

As Michael Kay mentioned in the comments, this is not the XML that the parser is seeing. You have to find the XML that the parser is actually seeing to solve your problem:

  • You might have a dirty buffer problem. Make sure that buffer you're handing to the parser has been cleared prior to adding your XML.
  • You might be passing a different filename than the one associated with the file you think is being parsed.
  • An earlier stage in your pipeline might be changing the XML prior to the parsing in question.
  • ...

Try to dump the XML being given to the parser immediately prior to parsing so that you can be sure you're looking at what the parser is reading. It is also conceivable, although not common/likely with most parsers I've seen, that the parser has not been properly initialized or reset after a prior run. Really, focus on finding what the parser is really seeing to hone in on your problem.

Community
  • 1
  • 1
kjhughes
  • 106,133
  • 27
  • 181
  • 240