コード例 #1
0
        public virtual Object ReadFromStream(Stream inputStream, Encoding encoding)
        {
            //Stream memoryStream = new MemoryStream();
            //int b;
            //while ((b = inputStream.ReadByte()) != -1)
            //{
            //    memoryStream.WriteByte((byte)b);
            //}
            //memoryStream.Position = 0;
            //String xml = new StreamReader(memoryStream).ReadToEnd();
            String xml = "n/a";
            //memoryStream.Position = 0;
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.DtdProcessing    = DtdProcessing.Prohibit;
            //settings.ValidationType = ValidationType.None;
            settings.XmlResolver = null;

            XmlReader reader = XmlReader.Create(new StreamReader(inputStream, encoding), settings);

            try
            {
                DefaultXmlReader pullParserReader = new DefaultXmlReader(reader, XmlController, ObjectFutureHandlerRegistry);
                if (!XmlDictionary.RootElement.Equals(pullParserReader.GetElementName()))
                {
                    pullParserReader.NextTag();
                }
                if (!XmlDictionary.RootElement.Equals(pullParserReader.GetElementName()))
                {
                    throw new Exception("Invalid root element: " + pullParserReader);
                }
                pullParserReader.NextTag();
                Object obj = pullParserReader.ReadObject();
                obj = PostProcess(obj, pullParserReader);

                return(obj);
            }
            catch (XmlTypeNotFoundException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new Exception("Error while parsing xml: " + xml, e);
            }
        }
コード例 #2
0
        public virtual Object ReadFromReader(TextReader textReader)
        {
            XmlReaderSettings settings = new XmlReaderSettings();

            settings.IgnoreWhitespace = true;
            settings.DtdProcessing    = DtdProcessing.Prohibit;
            //settings.ValidationType = ValidationType.None;
            settings.XmlResolver = null;

            XmlReader reader = XmlReader.Create(textReader, settings);

            try
            {
                DefaultXmlReader pullParserReader = new DefaultXmlReader(reader, XmlController, ObjectFutureHandlerRegistry);
                reader.Read();

                if (!XmlDictionary.RootElement.Equals(pullParserReader.GetElementName()))
                {
                    throw new Exception("Invalid root element: " + pullParserReader);
                }
                pullParserReader.NextTag();
                Object obj = pullParserReader.ReadObject();
                obj = PostProcess(obj, pullParserReader);

                return(obj);
            }
            catch (XmlTypeNotFoundException)
            {
                throw;
            }
            catch (Exception e)
            {
                //if (reader != null)
                //{
                //    throw new Exception(
                //            "Error while parsing cyclic xml content (line " + reader.LgetLineNumber() + ", column " + reader.getColumnNumber(), e);
                //}
                Log.Error(e);
                throw;
            }
        }