.net - XmlSerializer: How to capture file/line/column information for each deserialized element? -
I am using XML serialization to read a larger user input file. If there is a semantic error in the input that is not discovered during reading, then I can tell the user where (file, line, column) they can get ridiculous elements, is it possible with XML serialization?
Clarification: The code in question is an IOC container for compact framework; Many of the possible meaning errors are related to things like reflection failures when starting the last object graph. These are effective timing errors, but there are no errors in reading-time or compilation-time, however, I would like to tell them that there was no failure of the property because the property in the class room is not Fred but the fixed asset objects in the question xx Is on line 1337
- Errors are not result in deserialization exceptions The input is valid for deserialization purposes and does not include any syntax or data type errors.
- Errors can not be detected by enabling schema verification. Input is schematically valid.
- Errors can not be detected during the reading / deserialization process because the type of object object can not be solved yet.
If you have schemas describing the document, when you do deserialize , Then you can use XmlReader with validation. Handle verification errors and you'll be able to give more details to your users than their choices.
Note that XML schema validation errors are not very user-friendly. You may want to work in the opposite direction: Make your documents hard to input invalid documents. Using tools like Infopath, which puts a form use on XML instance documents, there will be a way to do this.
Another way is to use XML Editor in Visual Studio Express 2008. If you provide it with schema, it will not only validate the XML, it will also provide the intelligence - it will show next valid elements or attributes, and tooltips to be documented with schema.
There will be no way to do whatever you are looking for. Many of these semantic failures are referring to you, will show exceptions somewhere in the sorting process. The first of these exceptions will end the process. You can only catch such an exception outside of your call at XmlSerializer.Deserialize
. At that point, any reference has ended, and you have a series of exceptions. InnerException.InnerException ...
If you implement your own deserialization by implementing IXmlSerializable
, you will be able to maintain exception handling inside the class, which is used by XmlReader Is being used for the use of. If the reader keeps information about the line and column, then you should be able to add that information to the exception.
Comments
Post a Comment