0

My requirement is to read an XML file and to read the inner-text of some specific nodes. The XML files will be created manually by user and a few of the nodes may have XML node like value. for eg:

<Books>
  <Book Name ="ABC">
    <author>abc</author>
  </Book>
  <Book Name ="XYZ">
    <author><xyz></author>
  </Book>
</Book>

Though this will create an XML file with incorrect syntax, my code should be able to handle this and should read the XML file. Can anyone suggest how to do this?

SVM
  • 15
  • 1
  • 5
  • It might be easier to ask the creator to write proper XML. Is that a possibility? – default May 22 '15 at 10:57
  • it might not be a duplicate, but the two answers from [here](http://stackoverflow.com/q/1069114/238902) describes some of the issues with incorrect XML. – default May 22 '15 at 11:00
  • You could replace the `` with `<xyz>` - Before placing it in the XML... Other than that you may have to write your own parser. For a normal parser checkout this: http://stackoverflow.com/questions/1238528/ . For writing your own parser, it might be worth doing a google first. – Jimmyt1988 May 22 '15 at 11:01
  • 2
    The example is not valid XML. If the end user is hand tooling the XML in a text editor then they are responsible to ensure it is valid. If you are providing a front end where you capture the fields and then format this into XML then your code is responsible to correctly encode the data as XML (see @Jimmyt1988 answer for the correct encoding). – THBBFT May 22 '15 at 11:08
  • You can try to [fix it using HtmlAgilityPack](http://stackoverflow.com/a/30302828/2998271). – har07 May 22 '15 at 11:26
  • Use a schema when user creates xml so error don't occur. – jdweng May 22 '15 at 11:44
  • What are you thinking to do with `` - just close it? or say the error to user? – splash58 May 22 '15 at 12:15

0 Answers0