public void ReadXml(System.Xml.XmlReader reader)
        {
            XmlSerializer valueSerializer = new XmlSerializer(typeof(TValue));

            //Turn normalization off..
            if (reader.GetType() == typeof(XmlTextReader))
            {
                ((XmlTextReader)reader).Normalization = false;
            }

            bool wasEmpty = reader.IsEmptyElement;

            reader.Read();

            if (wasEmpty)
            {
                return;
            }

            while (reader.NodeType != System.Xml.XmlNodeType.EndElement)
            {
                reader.ReadStartElement("item");

                reader.ReadStartElement("value");
                TValue value = (TValue)valueSerializer.Deserialize(reader);
                reader.ReadEndElement();

                this.Add(value);

                reader.ReadEndElement();
                reader.MoveToContent();
            }
            reader.ReadEndElement();
        }
Example #2
0
 internal void Load(XmlDocument doc, XmlReader reader, bool preserveWhitespace)
 {
     this.doc = doc;
     if (reader.GetType() == typeof(XmlTextReader))
     {
         this.reader = ((XmlTextReader)reader).Impl;
     }
     else
     {
         this.reader = reader;
     }
     this.preserveWhitespace = preserveWhitespace;
     if (doc == null)
     {
         throw new ArgumentException(Res.GetString("Xdom_Load_NoDocument"));
     }
     if (reader == null)
     {
         throw new ArgumentException(Res.GetString("Xdom_Load_NoReader"));
     }
     doc.SetBaseURI(reader.BaseURI);
     if ((reader.Settings != null) && (reader.Settings.ValidationType == ValidationType.Schema))
     {
         doc.Schemas = reader.Settings.Schemas;
     }
     if ((this.reader.ReadState == ReadState.Interactive) || this.reader.Read())
     {
         this.LoadDocSequence(doc);
     }
 }
        internal XNodeReaderLineNumberService(XmlModelProvider xmlModelProvider, XmlReader xmlReader, Uri uri)
            : base(xmlModelProvider)
        {
            Debug.Assert(xmlReader != null, "xmlReader != null");
            Debug.Assert(uri != null, "uri != null");

            Debug.Assert(
                xmlReader.GetType().Name == "XNodeReader",
                "Unexpected type for XmlReader.  Expected reader to be System.Xml.Linq.XNodeReader");

            Debug.Assert(_sourceFieldInfo != null, "_sourceFieldInfo != null");
            Debug.Assert(_parentFieldInfo != null, "_parentFieldInfo != null");

            _xmlReader = xmlReader;
            _uri = uri;
        }
Example #4
0
		public static void AssertNode (
			string label,
			XmlReader xmlReader,
			XmlNodeType nodeType,
			int depth,
			bool isEmptyElement,
			string name,
			string prefix,
			string localName,
			string namespaceURI,
			string value,
			bool hasValue,
			int attributeCount,
			bool hasAttributes)
		{
			label = String.Concat (label, "(", xmlReader.GetType ().Name, ")");
			Assert.AreEqual (nodeType, xmlReader.NodeType, label + ".NodeType");
			Assert.AreEqual (isEmptyElement, xmlReader.IsEmptyElement,
				label + ".IsEmptyElement");

			Assert.AreEqual (name, xmlReader.Name, label + ".Name");

			Assert.AreEqual (prefix, xmlReader.Prefix, label + ".Prefix");

			Assert.AreEqual (localName, xmlReader.LocalName, label + ".LocalName");

			Assert.AreEqual (namespaceURI, xmlReader.NamespaceURI, label + ".NamespaceURI");

			Assert.AreEqual (depth, xmlReader.Depth, label + ".Depth");

			Assert.AreEqual (hasValue, xmlReader.HasValue, label + ".HasValue");

			Assert.AreEqual (value, xmlReader.Value, label + ".Value");

			Assert.AreEqual (hasAttributes, xmlReader.HasAttributes,
				label + "HasAttributes");

			Assert.AreEqual (attributeCount, xmlReader.AttributeCount,
				label + ".AttributeCount");
		}
Example #5
0
 internal void Load(XmlDocument doc, XmlReader reader, bool preserveWhitespace)
 {
     _doc = doc;
     // perf: unwrap XmlTextReader if no one derived from it
     if (reader.GetType() == typeof(System.Xml.XmlTextReader))
     {
         _reader = ((XmlTextReader)reader).Impl;
     }
     else
     {
         _reader = reader;
     }
     _preserveWhitespace = preserveWhitespace;
     if (doc == null)
     {
         throw new ArgumentException(SR.Xdom_Load_NoDocument);
     }
     if (reader == null)
     {
         throw new ArgumentException(SR.Xdom_Load_NoReader);
     }
     doc.SetBaseURI(reader.BaseURI);
     if (reader.Settings != null &&
         reader.Settings.ValidationType == ValidationType.Schema)
     {
         doc.Schemas = reader.Settings.Schemas;
     }
     if (_reader.ReadState != ReadState.Interactive)
     {
         if (!_reader.Read())
         {
             return;
         }
     }
     LoadDocSequence(doc);
 }
 internal void Load(XmlDocument doc, XmlReader reader, bool preserveWhitespace)
 {
     this.doc = doc;
     if (reader.GetType() == typeof(XmlTextReader))
     {
         this.reader = ((XmlTextReader) reader).Impl;
     }
     else
     {
         this.reader = reader;
     }
     this.preserveWhitespace = preserveWhitespace;
     if (doc == null)
     {
         throw new ArgumentException(Res.GetString("Xdom_Load_NoDocument"));
     }
     if (reader == null)
     {
         throw new ArgumentException(Res.GetString("Xdom_Load_NoReader"));
     }
     doc.SetBaseURI(reader.BaseURI);
     if ((reader.Settings != null) && (reader.Settings.ValidationType == ValidationType.Schema))
     {
         doc.Schemas = reader.Settings.Schemas;
     }
     if ((this.reader.ReadState == ReadState.Interactive) || this.reader.Read())
     {
         this.LoadDocSequence(doc);
     }
 }