/// <summary> /// /// </summary> /// <param name="tag"></param> private void SkipTag(string tag) { Stack <String> startElements = new Stack <string>(); startElements.Push(tag); while (NextEvent()) { switch (_xmlReader.NodeType) { case XmlNodeType.Element: if (CurrentTag.Equals(tag) && !_xmlReader.IsEmptyElement) { startElements.Push(tag); } break; case XmlNodeType.EndElement: if (CurrentTag.Equals(tag)) { startElements.Pop(); } break; } if (startElements.Count <= 0) { break; } } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="currentFieldDescriptor"></param> private void DeserializeWrappedComposite(object root, FieldDescriptor currentFieldDescriptor) { String currentTag = CurrentTag; while (NextEvent() && !(_xmlReader.NodeType == XmlNodeType.EndElement && CurrentTag.Equals(currentTag))) { DeserializeComposite(root, currentFieldDescriptor); } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="fd"></param> private void DeserializeScalarCollection(object root, FieldDescriptor fd) { String currentTag = CurrentTag; while (NextEvent() && !(_xmlReader.NodeType == XmlNodeType.EndElement && CurrentTag.Equals(currentTag))) { DeserializeScalarCollectionElement(root, fd); } }
/// <summary> /// /// </summary> /// <param name="root"></param> /// <param name="rootClassDescriptor"></param> /// <param name="rootTag"></param> private void CreateObjectModel(object root, ClassDescriptor rootClassDescriptor, string rootTag) { FieldDescriptor currentFieldDescriptor = new FieldDescriptor(); while (NextEvent() && (_xmlReader.NodeType != XmlNodeType.EndElement || !CurrentTag.Equals(rootTag))) { if (_xmlReader.NodeType != XmlNodeType.Element) { continue; } if (currentFieldDescriptor.FdType != FieldTypes.Wrapper) { currentFieldDescriptor = rootClassDescriptor.GetFieldDescriptorByTag(CurrentTag); } if (currentFieldDescriptor == null) { //Debug.WriteLine("ignoring tag " + CurrentTag); currentFieldDescriptor = FieldDescriptor.MakeIgnoredFieldDescriptor(CurrentTag); if (!_xmlReader.IsEmptyElement) { SkipTag(CurrentTag); } continue; } switch (currentFieldDescriptor.FdType) { case FieldTypes.Scalar: DeserializeScalar(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeComposite(root, currentFieldDescriptor); break; case FieldTypes.CollectionScalar: DeserializeScalarCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollectionElement(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMapElement(root, currentFieldDescriptor); break; case FieldTypes.Wrapper: currentFieldDescriptor = currentFieldDescriptor.WrappedFd; switch (currentFieldDescriptor.FdType) { case FieldTypes.CollectionScalar: DeserializeScalarCollection(root, currentFieldDescriptor); break; case FieldTypes.CollectionElement: DeserializeCompositeCollection(root, currentFieldDescriptor); break; case FieldTypes.MapElement: DeserializeCompositeMap(root, currentFieldDescriptor); break; case FieldTypes.CompositeElement: DeserializeWrappedComposite(root, currentFieldDescriptor); break; } break; case FieldTypes.IgnoredElement: SkipTag(CurrentTag); break; default: NextEvent(); break; } } DeserializationPostHook(root, translationContext); if (deserializationHookStrategy != null) { deserializationHookStrategy.DeserializationPostHook(root, null); } }