Click here to Skip to main content
16,005,206 members
Home / Discussions / C#
   

C#

 
GeneralRe: Attributes giving problem Pin
PIEBALDconsult8-Nov-07 16:58
mvePIEBALDconsult8-Nov-07 16:58 
AnswerRe: Attributes giving problem Pin
Nissim Salomon9-Nov-07 0:15
Nissim Salomon9-Nov-07 0:15 
QuestionHow to Send Parameter(s) to Reporting Service ? Pin
hdv2128-Nov-07 4:34
hdv2128-Nov-07 4:34 
AnswerRe: How to Send Parameter(s) to Reporting Service ? Pin
Giorgi Dalakishvili8-Nov-07 6:23
mentorGiorgi Dalakishvili8-Nov-07 6:23 
GeneralRe: How to Send Parameter(s) to Reporting Service ? Pin
hdv2128-Nov-07 11:32
hdv2128-Nov-07 11:32 
GeneralRe: How to Send Parameter(s) to Reporting Service ? Pin
Giorgi Dalakishvili8-Nov-07 20:15
mentorGiorgi Dalakishvili8-Nov-07 20:15 
QuestionXML Deserialisation & Malformed XML [modified] Pin
MrEyes8-Nov-07 4:23
MrEyes8-Nov-07 4:23 
AnswerRe: XML Deserialisation & Malformed XML Pin
MrEyes8-Nov-07 4:58
MrEyes8-Nov-07 4:58 
It would seem I have found the solution, a tweak to the code above and malformed XML is no longer allowed:

static void Main(string[] args)
{
    //input XML
    string rawXml = "<TestSchema>";
    rawXml += "<Widgets>A value for widgets</Widgets>";
    rawXml += "<LaLa>Hold on whats this an element that doesnt exist in the schema</LaLa>";
    rawXml += "</TestSchema>";

    //deserialise
    XmlSerializer s = new XmlSerializer(typeof(TestSchema));
    byte[] buffer = ASCIIEncoding.UTF8.GetBytes(rawXml);
    MemoryStream ms = new MemoryStream(buffer);
    XmlReader reader = new XmlTextReader(ms);

    XmlDeserializationEvents deserializationEvents = new XmlDeserializationEvents();
    deserializationEvents.OnUnknownAttribute = new XmlAttributeEventHandler(UnknownAttributeEventHandler);
    deserializationEvents.OnUnknownElement = new XmlElementEventHandler(UnknownElementEventHandler);
    deserializationEvents.OnUnknownNode = new XmlNodeEventHandler(UnknownNodeEventHandler);
    deserializationEvents.OnUnreferencedObject = new UnreferencedObjectEventHandler(UnreferencedObjEventHandler);

    TestSchema obj = (TestSchema)s.Deserialize(reader, deserializationEvents);

    reader.Close();

    //output
    Console.WriteLine(obj.GetHashCode());
    Console.ReadLine();
}

private static void UnknownAttributeEventHandler(object sender, XmlAttributeEventArgs e)
{
    //handle event condition
}

private static void UnknownElementEventHandler(object sender, XmlElementEventArgs e)
{
    //handle event condition
}

private static void UnknownNodeEventHandler(object sender, XmlNodeEventArgs e)
{
    //handle event condition
}

private static void UnreferencedObjEventHandler(object sender, UnreferencedObjectEventArgs e)
{
    //handle event condition
}


As you can see in the code above, the XmlSerializer.Deserialize can also take an instance of XmlDeserializationEvents. If this is setup and passed in these events are created and from there I can handle the error condition.
GeneralRe: XML Deserialisation &amp; Malformed XML Pin
J4amieC8-Nov-07 6:14
J4amieC8-Nov-07 6:14 
GeneralRe: XML Deserialisation &amp; Malformed XML Pin
MrEyes8-Nov-07 6:49
MrEyes8-Nov-07 6:49 
Questionshow/hide detection Pin
Morad SAJID8-Nov-07 3:36
Morad SAJID8-Nov-07 3:36 
AnswerRe: show/hide detection Pin
Pete O'Hanlon8-Nov-07 3:40
mvePete O'Hanlon8-Nov-07 3:40 
GeneralRe: show/hide detection Pin
Morad SAJID8-Nov-07 4:13
Morad SAJID8-Nov-07 4:13 
GeneralRe: show/hide detection Pin
AliAmjad8-Nov-07 4:20
AliAmjad8-Nov-07 4:20 
GeneralRe: show/hide detection Pin
Morad SAJID8-Nov-07 4:29
Morad SAJID8-Nov-07 4:29 
GeneralRe: show/hide detection Pin
Kristian Sixhøj8-Nov-07 4:38
Kristian Sixhøj8-Nov-07 4:38 
GeneralRe: show/hide detection Pin
Pete O'Hanlon8-Nov-07 4:42
mvePete O'Hanlon8-Nov-07 4:42 
GeneralRe: show/hide detection Pin
Morad SAJID8-Nov-07 4:48
Morad SAJID8-Nov-07 4:48 
GeneralRe: show/hide detection Pin
Pete O'Hanlon8-Nov-07 5:16
mvePete O'Hanlon8-Nov-07 5:16 
GeneralRe: show/hide detection Pin
Morad SAJID8-Nov-07 5:21
Morad SAJID8-Nov-07 5:21 
AnswerRe: show/hide detection Pin
Michael Potter8-Nov-07 5:18
Michael Potter8-Nov-07 5:18 
QuestionHelp with SQL Server Connection Pin
MumbleB8-Nov-07 3:22
MumbleB8-Nov-07 3:22 
AnswerRe: Help with SQL Server Connection Pin
Pete O'Hanlon8-Nov-07 3:27
mvePete O'Hanlon8-Nov-07 3:27 
QuestionUrjent Pin
imatetvm8-Nov-07 3:14
imatetvm8-Nov-07 3:14 
AnswerRe: Urjent Pin
Pete O'Hanlon8-Nov-07 3:24
mvePete O'Hanlon8-Nov-07 3:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.