/// <summary> /// Deserialize an <see cref="System.Xml.XmlTextReader"/> pointing to a WDDX packet. /// </summary> /// <param name="input">The pre-initialized <see cref="System.Xml.XmlTextReader"/> pointing to the WDDX to be parsed.</param> /// <param name="validate"> /// Boolean indicating whether or not validation should be performed during deserialization. /// </param> /// <remarks> /// If <c>validate</c> is set to <c>true</c>, this method will throw a <see cref="WddxValidationException"/> /// if it encounters invalid WDDX. /// /// Note that ColdFusion can produce <c>dateTime</c> elements that the WDDX XML Schema /// cannot validate, so this method may throw a <see cref="WddxValidationException"/> /// for packets that can be successfully deserialized if validation is turned off. /// </remarks> /// <exception cref="WddxValidationException"> /// The <c>validate</c> parameter is set to <c>true</c> and invalid WDDX is encountered. /// </exception> public object Deserialize(XmlTextReader input, bool validate) { if (validate) { WddxValidator validator = new WddxValidator(); return validator.Deserialize(input); } else { IWddxElementDeserializer deserializer; object retVal = null; int a = 0; while (input.Read()) { try { a++; //ignore whitespace nodetype, this is most likely introduced when XML is formatted for human reading if (input.NodeType == XmlNodeType.Element && input.Name == "data" && input.NodeType != XmlNodeType.Whitespace) { // advance to next node after <data> this that is not whitespace input.Read(); while (input.NodeType == XmlNodeType.Whitespace) { input.Read(); }; deserializer = WddxElementDeserializerFactory.GetDeserializer(input.Name); retVal = deserializer.ParseElement(input); } } catch (Exception e) { throw new WddxValidationException("Validation error parsing WDDX packet (C) at node index " + a + ":", e.Message); } } return retVal; } }
/// <summary> /// Validates the given WDDX packet against the WDDX XML Schema, /// and indicates whether or not the packet passed validation. /// </summary> /// <remarks> /// ColdFusion can produce <c>dateTime</c> elements that the WDDX XML Schema /// cannot validate, so this method may return <b>false</b> for packets that /// can be successfully deserialized. /// </remarks> /// <param name="input">The pre-initialized <see cref="System.Xml.XmlTextReader"/> pointing to the WDDX to be validated.</param> /// <returns>Returns <c>true</c> if the packet passes validation, <c>false</c> if it does not.</returns> public bool IsValid(XmlTextReader input) { WddxValidator validator = new WddxValidator(); return validator.IsValid(input); }