System.Xml.Serialization.XmlSerializer.UnreferencedObject Event

Occurs during deserialization of a SOAP-encoded XML stream, when the System.Xml.Serialization.XmlSerializer encounters a recognized type that is not used or is unreferenced.

Syntax

public event UnreferencedObjectEventHandler UnreferencedObject

Remarks

The XmlSerializer.UnreferencedObject event only occurs when the System.Xml.Serialization.XmlSerializer is used to deserialize an XML document that contains a SOAP message that conforms to section 5 of the World Wide Web Consortium (www.w3.org) document, "Simple Object Access Protocol (SOAP) 1.1".

Documents that conform to section 5 are in a special format. At the very least, such a document includes the main body of the SOAP message. However, rather than having all types defined inline in the document, some type definitions can be encoded as references to top-level elements in the document. Thus, for every element found in the main body that is a reference, there must be a corresponding element that contains the type definition. To correlate the referencing element and the type definition, the type definition has an id attribute set to a unique string ID and the referencing element has an href attribute that references the same ID.

Example

 <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" id="id1" n1:GroupName=".NET" GroupNumber="ZDI=" CreationDate="2002-05-02" xmlns:n1="http:'www.cpandl.com">
     <PosInt xsi:type="xsd:nonNegativeInteger">10000</PosInt>
     <GroupVehicle href="#id2" />
   </Group>
   <Vehicle id="id2" n1:type="Vehicle" xmlns:n1="http://www.w3.org/2001/XMLSchema-instance">
     <licenseNumber xmlns:q1="http://www.w3.org/2001/XMLSchema" n1:type="q1:string">1234</licenseNumber>
   </Vehicle>

The XmlSerializer.UnreferencedObject event occur when there is a type definition found in the document, but no parameter in the main body references it. When the event occurs, you can retrieve the XML type of the unreferenced object by examining the UnreferencedObjectEventArgs.UnreferencedObject property of the System.Xml.Serialization.UnreferencedObjectEventArgs class. The XML ID of the object is returned by the UnreferencedObjectEventArgs.UnreferencedId property.

The XmlSerializer.UnreferencedObject event should not be confused with the XmlSerializer.UnknownElement and XmlSerializer.UnknownNode events, which occur when there is no class member that corresponds to the XML node or element type.

Requirements

Namespace: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0