Click here to Skip to main content
15,887,596 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
XML
<corn>85455555</corn>
     <numBtch>12674</numBtch>
     <idSend>273370857-----Here tag is missing
     <nmSend>Test Data</nmSend>



How i can add that that missing tag. I know how to find location

The 'idSend' start tag on line 7 position 5 does not match the end tag of 'hdr'. Line 25, position 5.


But dont know how to add that

What I have tried:

Not able to think what i can try
Posted
Updated 31-Mar-23 2:03am
v2
Comments
Dave Kreskowiak 29-Mar-23 17:34pm    
Is there any reason why the code that generated the XML file cannot be fixed to generate a correct file?
Member 15965418 30-Mar-23 13:42pm    
missing end tag file i am getting from 3rd party application, cant ask them to fix it.
Dave Kreskowiak 30-Mar-23 13:49pm    
Well, you're going to HAVE to go back to them and tell them to fix their "broken ass sh*t".

You can TRY To fix it with code, but that's no guarantee that the one problem you've posted is the only type of problem the file will have. How can to trust the data is complete and well formed and formatted? You can't!

Every XML loader in the .NET Framework will not load a malformed document, so you're going to have to write your own XML parser to load the document WHILE fixing problems that YOU tell it how to identify these problems and fix them. That is not a small job and it's going to tak e you longer than a week or two to write it.

Good Luck!
Member 15965418 30-Mar-23 14:09pm    
Can i convert my xml to word then fix the error and again convert to xml file? just thinking
Dave Kreskowiak 30-Mar-23 15:33pm    
Why on earth would you use Word to do anything with an XML file?

1 solution

There is no automated way to "fix" badly formed XML - you need to "know" what the expected structure should be, and since the XML is all you get and it defines the structure of the data it contains, that can't be inferred from the defective data.

That's why the error message refers to lines 7 and 25 - it;'s telling you that there is an opening <idSend> tag on line 7 but that no closing </idSend> tag was encountered before the file ended on line 25.

The best solution is to go back to the data source, and get that fixed to generate properly formed XML data - because the alternative is to write your own XML reader which knowns what the data structure is supposed to be, and which can ignore missing close tags. That's a lot of work, and assumes that there are no other nasties in the data source which will become apparent later ... in production this time!
 
Share this answer
 
Comments
Member 15965418 30-Mar-23 13:43pm    
missing end tag file i am getting from 3rd party application, cant ask them to fix it. So i need to fix that :(
Member 15965418 30-Mar-23 13:43pm    
Thanks for your valuable comments.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900