Example #1
0
        internal XmlNamespaceManager ParsePartialContent(XmlNode parentNode, string innerxmltext, XmlNodeType nt)
        {
            //the function shouldn't be used to set innerxml for XmlDocument node
            Debug.Assert(parentNode.NodeType != XmlNodeType.Document);
            _doc = parentNode.OwnerDocument;
            Debug.Assert(_doc != null);
            XmlParserContext pc = GetContext(parentNode);
            _reader = CreateInnerXmlReader(innerxmltext, nt, pc, _doc);
            try
            {
                _preserveWhitespace = true;
                bool bOrigLoading = _doc.IsLoading;
                _doc.IsLoading = true;

                if (nt == XmlNodeType.Entity)
                {
                    XmlNode node = null;
                    while (_reader.Read() && (node = LoadNodeDirect()) != null)
                    {
                        parentNode.AppendChildForLoad(node, _doc);
                    }
                }
                else
                {
                    XmlNode node = null;
                    while (_reader.Read() && (node = LoadNode(true)) != null)
                    {
                        parentNode.AppendChildForLoad(node, _doc);
                    }
                }
                _doc.IsLoading = bOrigLoading;
            }
            finally
            {
                _reader.Dispose();
            }
            return pc.NamespaceManager;
        }
Example #2
0
 private XmlReader NestRead(XmlReader r)
 {
     r.Read();
     r.Read();
     if (!(r.Name == "elem0" && r.NodeType == XmlNodeType.Element))
     {
         NestRead(r.ReadSubtree());
     }
     r.Dispose();
     return r;
 }
Example #3
0
        public int TransformResolver(String szXmlFile, XmlResolver xr, bool errorCase)
        {
            lock (s_outFileMemoryLock)
            {
                szXmlFile = FullFilePath(szXmlFile);

                _output.WriteLine("Loading XML {0}", szXmlFile);
                IXPathNavigable xd = LoadXML(szXmlFile, _docType);

                _output.WriteLine("Executing transform");
                xrXSLT = null;
                Stream strmTemp = null;

                switch (_nTransform)
                {
                    case TransformType.Reader:
                        xrXSLT = xslt.Transform(xd, null, xr);
                        if (errorCase)
                        {
                            try
                            {
                                while (xrXSLT.Read()) { }
                            }
                            catch (Exception ex)
                            {
                                throw (ex);
                            }
                            finally
                            {
                                if (xrXSLT != null)
                                    xrXSLT.Dispose();
                            }
                        }
                        break;

                    case TransformType.Stream:
                        try
                        {
                            strmTemp = new FileStream(_strOutFile, FileMode.Create, FileAccess.ReadWrite);
                            xslt.Transform(xd, null, strmTemp, xr);
                        }
                        catch (Exception ex)
                        {
                            throw (ex);
                        }
                        finally
                        {
                            if (strmTemp != null)
                                strmTemp.Dispose();
                        }
                        break;

                    case TransformType.Writer:
                        XmlWriter xw = null;
                        try
                        {
                            xw = new XmlTextWriter(_strOutFile, Encoding.UTF8);
                            xw.WriteStartDocument();
                            xslt.Transform(xd, null, xw, xr);
                        }
                        catch (Exception ex)
                        {
                            throw (ex);
                        }
                        finally
                        {
                            if (xw != null)
                                xw.Dispose();
                        }
                        break;

                    case TransformType.TextWriter:
                        TextWriter tw = null;
                        try
                        {
                            tw = new StreamWriter(new FileStream(_strOutFile, FileMode.Create, FileAccess.Write), Encoding.UTF8);
                            xslt.Transform(xd, null, tw, xr);
                        }
                        catch (Exception ex)
                        {
                            throw (ex);
                        }
                        finally
                        {
                            if (tw != null)
                                tw.Dispose();
                        }
                        break;
                }
                return 1;
            }
        }
Example #4
0
        public void Load(string _strXslFile, string _strXmlFile)
        {
            _xrData = XmlReader.Create(_strPath + _strXmlFile);
            _xd = new XPathDocument(_xrData, XmlSpace.Preserve);
            _xrData.Dispose();

            XmlReaderSettings xrs = new XmlReaderSettings();
#pragma warning disable 0618
            xrs.ProhibitDtd = false;
#pragma warning restore 0618
            XmlReader xrTemp = XmlReader.Create(_strPath + _strXslFile, xrs);
            xsltSameInstance.Load(xrTemp);
        }
        private void LoadFromConfigXmlReader(ConfigXmlReader reader)
        {
            IConfigErrorInfo err = (IConfigErrorInfo) reader;
            _filename = err.Filename;
            _lineOffset = err.LineNumber + 1;

            try {
                _reader = reader;
                base.Load(_reader);
            }
            finally {
                if (_reader != null) {
                    _reader.Dispose();
                    _reader = null;
                }
            }
        }
 public void Load(string filename)
 {
     _filename = filename;
     try {
         _reader = XmlReader.Create(filename);
         //_reader.XmlResolver = null;
         base.Load(_reader);
     }
     finally {
         if (_reader != null) {
             _reader.Dispose();
             _reader = null;
         }
     }
 }
Example #7
0
        public bool CompareReader(XmlReader xrExpected, XmlDiffOption option)
        {
            bool bReturn = false;

            XmlReader xrActual = GetReader();

            XmlDiff diff = new XmlDiff();
            diff.Option = option;

            try
            {
                bReturn = diff.Compare(xrExpected, xrActual);
            }
            catch (Exception e)
            {
                CError.WriteLine(e);
            }
            finally
            {
                xrActual.Dispose();
                xrExpected.Dispose();
            }
            if (!bReturn)
            {
                CError.WriteLine("Mismatch in XmlDiff");
                CError.WriteLine("Actual o/p:");
                CError.WriteLine(this.GetString());
            }

            return bReturn;
        }
 private void destroyXmlReader(XmlReader xmlreader)
 {
     if (xmlreader != null)
     { xmlreader.Close(); xmlreader.Dispose(); }
 }