Note that there are some explanatory texts on larger screens.

plurals
  1. POHow would I parse an entire XML file that is possibly malformed?
    text
    copied!<p>So far, what I'm doing is:</p> <pre><code>try { XmlDocument xmldoc = loadXml(orderFilePath); } catch (XmlException exception) { //... blah blah - there was an error, let the user know } </code></pre> <p>But I would really like to be able to attempt to parse the file anyway. When I say "malformed" I don't necessarily mean that there will be an unclosed tag or element, but that there might be something like one of the following included in an element's value: '&lt;', '>', '&amp;'</p> <p>I've seen mentioned around that I would probably have to use XmlReader - but would that still throw an exception on that element, or allow me to fix the problem in some way?</p> <p>I know fixing the XML at the source is the best solution, but I do not control where the XML is coming from.</p> <p>Thanks!</p> <p>EDIT:</p> <p>Super simple example of the XML:</p> <pre><code>&lt;Order&gt; &lt;Customer_ID&gt;555-555-5555&lt;/Customer_ID&gt; &lt;ShipToAddress&gt; &lt;Customer_Name&gt;Some Guy&lt;/Customer_Name&gt; &lt;Street&gt;123 Fake Dr.&lt;/Street&gt; &lt;Street2&gt;&lt;/Street2&gt; &lt;City&gt;West Palm Beach&lt;/City&gt; &lt;State&gt;FL&lt;/State&gt; &lt;ZipCode&gt;33417&lt;/ZipCode&gt; &lt;Country&gt;United States&lt;/Country&gt; &lt;/ShipToAddress&gt; &lt;BillToAddress&gt; &lt;Customer_Name&gt;Some Guy&lt;/Customer_Name&gt; &lt;Street&gt;123 Fake Dr.&lt;/Street&gt; &lt;Street2&gt;&lt;/Street2&gt; &lt;City&gt;West Palm Beach&lt;/City&gt; &lt;State&gt;FL&lt;/State&gt; &lt;ZipCode&gt;33417&lt;/ZipCode&gt; &lt;Country&gt;United States&lt;/Country&gt; &lt;/BillToAddress&gt; &lt;items&gt; &lt;item&gt; &lt;Product_ID&gt;25101&lt;/Product_ID&gt; &lt;Product_Name&gt;&lt;/Product_Name&gt; &lt;Quantity&gt;1&lt;/Quantity&gt; &lt;USPrice&gt;26.95000&lt;/USPrice&gt; &lt;/item&gt; &lt;/items&gt; &lt;!-- bad stuff here --&gt; &lt;How_did_you_hear_about_us&gt;Coffee &amp; Tea magazine&lt;/How_did_you_hear_about_us&gt; &lt;!-- bad stuff here --&gt; &lt;/Order&gt; </code></pre> <p>The thing is - I don't necessarily know if it will always be in the same place.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload