private static DomObject CreateElement(XmlReader reader, DomMetaElement metaElement) { DomComplexType type = metaElement.Type; // Check for xsi:type attribute, indicating a derived type string typeName = reader.GetAttribute("xsi:type"); if (typeName != null) { // check for qualified type name string prefix = string.Empty; int index = typeName.IndexOf(':'); if (index >= 0) { prefix = typeName.Substring(0, index); index++; typeName = typeName.Substring(index, typeName.Length - index); } string ns = reader.LookupNamespace(prefix); XmlQualifiedName qualifiedName = new XmlQualifiedName(typeName, ns); type = DomSchemaRegistry.GetComplexType(qualifiedName); if (type == null) { throw new InvalidOperationException("Unknown derived type"); } } return(new DomObject(type)); }
private DomObject ReadInternal(Stream stream) { DomObject rootDomObject; using (XmlReader reader = XmlReader.Create(stream)) { reader.MoveToContent(); string ns = reader.NamespaceURI; XmlQualifiedName rootElementName = new XmlQualifiedName(reader.LocalName, ns); DomMetaElement rootElement = DomSchemaRegistry.GetRootElement(rootElementName); if (rootElement == null) { throw new InvalidOperationException("Unknown root element"); } rootDomObject = new DomObject(rootElement); ReadElement(rootDomObject, reader); reader.Close(); } return(rootDomObject); }