public class XmlNodeEventArgs : EventArgs
|
The XmlSerializer.UnknownNode event can occur only when you call the XmlSerializer.Deserialize method.
using System; using System.IO; using System.Xml; using System.Xml.Serialization; public class Group{ // Only the GroupName field will be known. public string GroupName; } public class Test{ static void Main(){ Test t = new Test(); t.DeserializeObject("UnknownNodes.xml"); } private void DeserializeObject(string filename){ XmlSerializer mySerializer = new XmlSerializer(typeof(Group)); FileStream fs = new FileStream(filename, FileMode.Open); mySerializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); Group myGroup = (Group) mySerializer.Deserialize(fs); fs.Close(); } protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e){ Console.WriteLine ("UnknownNode Name: {0}", e.Name); Console.WriteLine ("UnknownNode LocalName: {0}" ,e.LocalName); Console.WriteLine ("UnknownNode Namespace URI: {0}", e.NamespaceURI); Console.WriteLine ("UnknownNode Text: {0}", e.Text); XmlNodeType myNodeType = e.NodeType; Console.WriteLine("NodeType: {0}", myNodeType); Group myGroup = (Group) e.ObjectBeingDeserialized; Console.WriteLine("GroupName: {0}", myGroup.GroupName); Console.WriteLine(); } } /* Paste this XML into a file named UnknownNodes: <?xml version="1.0" encoding="utf-8"?> <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:coho = "http://www.cohowinery.com" xmlns:cp="http://www.cpandl.com"> <coho:GroupName>MyGroup</coho:GroupName> <cp:GroupSize>Large</cp:GroupSize> <cp:GroupNumber>444</cp:GroupNumber> <coho:GroupBase>West</coho:GroupBase> <coho:ThingInfo> <Number>1</Number> <Name>Thing1</Name> <Elmo> <Glue>element</Glue> </Elmo> </coho:ThingInfo> </Group> */
LineNumber | Read-only Gets the line number of the unknown XML node. |
LinePosition | Read-only Gets the position in the line of the unknown XML node. |
LocalName | Read-only Gets the XML local name of the XML node being deserialized. |
Name | Read-only Gets the name of the XML node being deserialized. |
NamespaceURI | Read-only Gets the namespace URI that is associated with the XML node being deserialized. |
NodeType | Read-only Gets the type of the XML node being deserialized. |
ObjectBeingDeserialized | Read-only Gets the object being deserialized. |
Text | Read-only Gets the text of the XML node being deserialized. |
Equals (inherited from System.Object) |
See base class member description: System.Object.Equals Derived from System.Object, the primary base class for all objects. |
GetHashCode (inherited from System.Object) |
See base class member description: System.Object.GetHashCode Derived from System.Object, the primary base class for all objects. |
GetType (inherited from System.Object) |
See base class member description: System.Object.GetType Derived from System.Object, the primary base class for all objects. |
ToString (inherited from System.Object) |
See base class member description: System.Object.ToString Derived from System.Object, the primary base class for all objects. |
Finalize (inherited from System.Object) |
See base class member description: System.Object.Finalize Derived from System.Object, the primary base class for all objects. |
MemberwiseClone (inherited from System.Object) |
See base class member description: System.Object.MemberwiseClone Derived from System.Object, the primary base class for all objects. |
Hierarchy:
public int LineNumber {get;}
|
using System; using System.IO; using System.Xml; using System.Xml.Serialization; public class Group{ // Only the GroupName field will be known. public string GroupName; } public class Test{ static void Main(){ Test t = new Test(); t.DeserializeObject("UnknownNodes.xml"); } private void DeserializeObject(string filename){ XmlSerializer mySerializer = new XmlSerializer(typeof(Group)); FileStream fs = new FileStream(filename, FileMode.Open); mySerializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); Group myGroup = (Group) mySerializer.Deserialize(fs); fs.Close(); } protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e){ Console.WriteLine ("UnknownNode Name: {0}", e.Name); Console.WriteLine ("UnknownNode LocalName: {0}" ,e.LocalName); Console.WriteLine ("UnknownNode Namespace URI: {0}", e.NamespaceURI); Console.WriteLine ("UnknownNode Text: {0}", e.Text); XmlNodeType myNodeType = e.NodeType; Console.WriteLine("NodeType: {0}", myNodeType); Group myGroup = (Group) e.ObjectBeingDeserialized; Console.WriteLine("GroupName: {0}", myGroup.GroupName); Console.WriteLine(); } } /* Paste this XML into a file named UnknownNodes: <?xml version="1.0" encoding="utf-8"?> <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:coho = "http://www.cohowinery.com" xmlns:cp="http://www.cpandl.com"> <coho:GroupName>MyGroup</coho:GroupName> <cp:GroupSize>Large</cp:GroupSize> <cp:GroupNumber>444</cp:GroupNumber> <coho:GroupBase>West</coho:GroupBase> <coho:ThingInfo> <Number>1</Number> <Name>Thing1</Name> <Elmo> <Glue>element</Glue> </Elmo> </coho:ThingInfo> </Group> */
public int LinePosition {get;}
|
using System; using System.IO; using System.Xml; using System.Xml.Serialization; public class Group{ // Only the GroupName field will be known. public string GroupName; } public class Test{ static void Main(){ Test t = new Test(); t.DeserializeObject("UnknownNodes.xml"); } private void DeserializeObject(string filename){ XmlSerializer mySerializer = new XmlSerializer(typeof(Group)); FileStream fs = new FileStream(filename, FileMode.Open); mySerializer.UnknownNode += new XmlNodeEventHandler(serializer_UnknownNode); Group myGroup = (Group) mySerializer.Deserialize(fs); fs.Close(); } protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e){ Console.WriteLine ("UnknownNode Name: {0}", e.Name); Console.WriteLine ("UnknownNode LocalName: {0}" ,e.LocalName); Console.WriteLine ("UnknownNode Namespace URI: {0}", e.NamespaceURI); Console.WriteLine ("UnknownNode Text: {0}", e.Text); XmlNodeType myNodeType = e.NodeType; Console.WriteLine("NodeType: {0}", myNodeType); Group myGroup = (Group) e.ObjectBeingDeserialized; Console.WriteLine("GroupName: {0}", myGroup.GroupName); Console.WriteLine(); } } /* Paste this XML into a file named UnknownNodes: <?xml version="1.0" encoding="utf-8"?> <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:coho = "http://www.cohowinery.com" xmlns:cp="http://www.cpandl.com"> <coho:GroupName>MyGroup</coho:GroupName> <cp:GroupSize>Large</cp:GroupSize> <cp:GroupNumber>444</cp:GroupNumber> <coho:GroupBase>West</coho:GroupBase> <coho:ThingInfo> <Number>1</Number> <Name>Thing1</Name> <Elmo> <Glue>element</Glue> </Elmo> </coho:ThingInfo> </Group> */
public string LocalName {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { Console.WriteLine ("UnknownNode LocalName: " + e.LocalName); }
public string Name {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { Console.WriteLine ("UnknownNode Name: " + e.Name); }
public string NamespaceURI {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { Console.WriteLine ("UnknownNode Namespace URI: " + e.NamespaceURI); }
public XmlNodeType NodeType {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { XmlNodeType myNodeType = e.NodeType; Console.WriteLine(myNodeType); }
public object ObjectBeingDeserialized {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { object o = e.ObjectBeingDeserialized; Console.WriteLine("Object being deserialized: " + o.ToString()); }
public string Text {get;}
|
protected void serializer_UnknownNode (object sender, XmlNodeEventArgs e) { Console.WriteLine ("UnknownNode Text: " + e.Text); }
~XmlNodeEventArgs(); |
public virtual int GetHashCode(); |
public Type GetType(); |
protected object MemberwiseClone(); |
public virtual string ToString(); |