Public void parse (string XML) {This. items = new rssitemcollection (); xmldocument xdoc = new xmldocument (); try {// xdoc. loadxml (XML); xdoc. loadxml (XML. trim ();} catch (exception e) {Throw new exception ("the content does not conform to the standard", e );}}
View code
During XML loading, the data at the root level is always invalid. Row 1, position 1
I have not found any results on the Internet for a long time. I only tried it myself. I added xml = xml before loading. trim (); passed, but there are no strange errors such as spaces before and after the XML, and the loaded XML is not reported in IE.
Dare not share it with others who share the same experience
From: http://hi.baidu.com/xsharkx/item/d2da2935cb6995f6a88428cc
Personal solution:
When a previously used XML file is loaded with only a few characters, "the root-level data is invalid. Although the above solution has been found and the problem has been solved
But it's not clear why?
Do strings that look exactly the same ??
Copy the following code to the chrome console and run it.
1 var s=‘<?xml version="1.0" encoding="UTF-8"?>‘;2 var s=‘<?xml version="1.0" encoding="UTF-8"?>‘;3 4 alert(‘s.length=‘+s.length+‘\r\n_s.length=‘+_s.length);
View code running result: Debugging in vs shows that there is one more character without trim ". "causes XML errors. Solution: 1. add trim () to the Code to clear unnecessary characters (recommended)
xDoc.LoadXml(xml.Trim());
2. automatically clear unnecessary characters "." and replace it in the XML file (this method does not completely avoid this issue should be used in method 1) http://hi.baidu.com/xsharkx/item/d2da2935cb6995f6a88428cc http://www.cnblogs.com/XChWaad/p/3346875.html