0

I trying to parse this xml string :

<form name="generatedForm" role="form">  <div class="form-group">    <label for="result">      Calculation Result    </label>    <input class="form-control" name="result" cam-variable-type="Long" cam-variable-name="result" type="text" />    <div ng-if="this.generatedForm.result.$invalid && this.generatedForm.result.$dirty" class="has-error">      <div ng-show="this.generatedForm.result.$error.required" class="help-block">        Required field      </div>      <div ng-show="this.generatedForm.result.$error.camVariableType" class="help-block">        Only a long value is allowed      </div>    </div>  </div>  <div class="form-group">    <label for="correcto">      es correcto?    </label>    <input class="form-control" name="correcto" cam-business-key type="checkbox" />    <div ng-if="this.generatedForm.correcto.$invalid && this.generatedForm.correcto.$dirty" class="has-error">      <div ng-show="this.generatedForm.correcto.$error.required" class="help-block">        Required field      </div>      <div ng-show="this.generatedForm.correcto.$error.camVariableType" class="help-block">        Only a boolean value is allowed      </div>    </div>  </div></form>

The code what I'm using is :

var x =XDocument.Parse("XmlString");

But i recieving System.Xml.XmlException: 'An error occurred while parsing EntityName. Line 1, position 290.'

I tried changig the encoding but the result is the same.

Thanks in advance.

Ivan Fontalvo
  • 433
  • 4
  • 21
  • 2
    Your XML is malformed. Upload it to https://www.xmlvalidation.com/ and you will get an error `1: 290 The entity name must immediately follow the '&' in the entity reference.`. The problem is with this attribute value: `
    – dbc Jul 28 '22 at 16:16
  • 2
    You need to escape `&` as `&` and also you cannot have attributes with no value. Is this HTML as opposed to XML? If so parse with HTMLAgilityPack – Charlieface Jul 28 '22 at 16:20
  • Yeah is an html and I trying to convert to xml to use linq to perform some searches after. – Ivan Fontalvo Jul 28 '22 at 16:22
  • HTML isn't XML. Consider using HTML Agility Pack as suggested in [C# - Parse HTML source as XML](https://stackoverflow.com/q/3016327) and [How to read HTML as XML?](https://stackoverflow.com/q/5472162). – dbc Jul 28 '22 at 16:28
  • Thanks, You are right , instead to manipulate the string as and xml is better to manipulate as an html (In this case) ... – Ivan Fontalvo Jul 28 '22 at 16:37

0 Answers0