Exemplo n.º 1
0
	// Constructor.
	public XmlDTDReader(XmlParserContext context)
			: base(null)
			{
				this.context = context;
				this.input = null;
				this.resolver = null;
			}
Exemplo n.º 2
0
    /// <summary>
    /// Returns the dataset loaded from the given document data.
    /// </summary>
    /// <param name="documentData">Document data to make the dataset from</param>
    /// <param name="taskType">Task type</param>
    /// <param name="taskObjectType">Task object type</param>
    protected virtual DataSet GetDataSet(string documentData, TaskTypeEnum taskType, string taskObjectType)
    {
        SyncHelper syncHelper = SyncHelper.GetInstance();
        syncHelper.OperationType = OperationTypeEnum.Synchronization;
        string className = CMSHierarchyHelper.GetNodeClassName(documentData, ExportFormatEnum.XML);
        DataSet ds = syncHelper.GetSynchronizationTaskDataSet(taskType, className, taskObjectType);

        XmlParserContext xmlContext = new XmlParserContext(null, null, null, XmlSpace.None);
        XmlReader reader = new XmlTextReader(documentData, XmlNodeType.Element, xmlContext);
        return DataHelper.ReadDataSetFromXml(ds, reader, null, null);
    }
Exemplo n.º 3
0
        private void ProcessQueue()
        {
            const string endStream = "</stream:stream>";

            while (true)
            {
                if (_xmpp.State is DisconnectedState || !_running)
                {
                    _logger.Log(LogLevel.Debug, "Disconnected or stopped");
                    break;
                }

                if (_dataQueue.Count <= 0)
                {
                    continue;
                }

                var message = _dataQueue.Dequeue();

                if (message.Contains(endStream))
                {
                    _logger.Log(LogLevel.Debug, "Ending stream and disconnecting");
                    _xmpp.State = new DisconnectState();
                    _xmpp.State.Execute(_xmpp);

                    if (message.Equals(endStream))
                    {
                        return;
                    }

                    message = message.Replace(endStream, string.Empty);
                }

                if (message.Contains("<stream:stream") && !message.Contains(endStream))
                {
                    _logger.Log(LogLevel.Debug, "Adding end tag");
                    message += endStream;
                }

                var context = new XmlParserContext(null, NamespaceManager, null, XmlSpace.None);
                var reader  = new XmlTextReader(message, XmlNodeType.Element, context);

                var root = XElement.Load(reader);

                var tag = _xmpp.Registry.GetTag <Tag>(root);
                _logger.Log(LogLevel.Debug, $"Found tag {tag}");

                OnTag(tag);
            }
        }
Exemplo n.º 4
0
    /// <summary>
    /// Returns the dataset loaded from the given document data.
    /// </summary>
    /// <param name="documentData">Document data to make the dataset from</param>
    /// <param name="taskType">Task type</param>
    /// <param name="taskObjectType">Task object type</param>
    protected virtual DataSet GetDataSet(string documentData, TaskTypeEnum taskType, string taskObjectType)
    {
        var man = SyncManager.GetInstance();

        man.OperationType = OperationTypeEnum.Synchronization;

        string  className = DocumentHierarchyHelper.GetNodeClassName(documentData, ExportFormatEnum.XML);
        DataSet ds        = man.GetSynchronizationTaskDataSet(taskType, className, taskObjectType);

        XmlParserContext xmlContext = new XmlParserContext(null, null, null, XmlSpace.None);
        XmlReader        reader     = new XmlTextReader(documentData, XmlNodeType.Element, xmlContext);

        return(DataHelper.ReadDataSetFromXml(ds, reader, null, null));
    }
Exemplo n.º 5
0
        public EntityResolvingXmlReader(XmlReader source)
        {
            this.source = source;
            IHasXmlParserContext container = source as IHasXmlParserContext;

            if (container != null)
            {
                this.context = container.ParserContext;
            }
            else
            {
                this.context = new XmlParserContext(source.NameTable, new XmlNamespaceManager(source.NameTable), null, XmlSpace.None);
            }
        }
        public void DublinCoreElementSet_LoadTest()
        {
            DublinCoreElementSetSyndicationExtension target = new DublinCoreElementSetSyndicationExtension();             // TODO: Initialize to an appropriate value
            var nt     = new NameTable();
            var ns     = new XmlNamespaceManager(nt);
            var xpc    = new XmlParserContext(nt, ns, "US-en", XmlSpace.Default);
            var strXml = ExtensionTestUtil.GetWrappedXml(namespc, strExtXml);

            using (XmlReader reader = new XmlTextReader(strXml, XmlNodeType.Document, xpc))
            {
                RssFeed feed = new RssFeed();
                feed.Load(reader);
            }
        }
Exemplo n.º 7
0
        public clsCTCheckOrderDomain()
        {
            //
            // TODO: Add constructor logic here
            //
            m_objXmlMemStream = new MemoryStream(300);

            m_objXmlWriter = new XmlTextWriter(m_objXmlMemStream, System.Text.Encoding.Unicode);
            m_objXmlWriter.Flush();            //賠腎圻栖議忖憲

            m_objXmlParser = new XmlParserContext(null, null, null, XmlSpace.None, Encoding.Unicode);

            //m_objServ =new com.digitalwave.CTCheckOrderServ.clsCTCheckOrderServ();
        }
    public static void Main()
    {
        XmlTextReader reader = null;

        try
        {
            //Create the XML fragment to be parsed.
            string xmlFrag = "<book> " +
                            "<title>Pride And Prejudice</title>" +
                            "<bk:genre>novel</bk:genre>" +
                            "</book>";

            //Create the XmlNamespaceManager that is used to
            //look up namespace information.
            NameTable nt = new NameTable();
            XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt);
            nsmgr.AddNamespace("bk", "urn:sample");

            //Create the XmlParserContext.
            XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

            //Implement the reader. 
            reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);

            //Parse the XML fragment.  If they exist, display the   
            //prefix and namespace URI of each element.
            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    if (reader.Prefix == String.Empty)
                        Console.WriteLine("<{0}>", reader.LocalName);
                    else
                    {
                        Console.Write("<{0}:{1}>", reader.Prefix, reader.LocalName);
                        Console.WriteLine(" The namespace URI is " + reader.NamespaceURI);
                    }
                }
            }


        }

        finally
        {
            if (reader != null)
                reader.Close();
        }
    }
Exemplo n.º 9
0
        static async Task copyStreamWithInterrupt(Process coqtop, Stream from, Stream to)
        {
            try
            {
                var settings = new XmlReaderSettings();
                settings.Async            = true;
                settings.CheckCharacters  = false;
                settings.ValidationType   = ValidationType.None;
                settings.ConformanceLevel = ConformanceLevel.Fragment;
                settings.DtdProcessing    = DtdProcessing.Parse;
                var context = new XmlParserContext(null, new XmlNamespaceManager(new NameTable()), null, XmlSpace.None, Encoding.UTF8);
                context.InternalSubset = "<!ENTITY nbsp \"&#160;\">";
                context.DocTypeName    = "coq";

                var reader = XmlTextReader.Create(from, settings, context);
                var writer = new StreamWriter(to);
                while (await reader.ReadAsync())
                {
                    if (reader.NodeType == XmlNodeType.Element && reader.Depth == 0 && reader.Name == "call" && reader.GetAttribute("val") == "Interrupt")
                    {
                        await Console.Error.WriteLineAsync("Sending ctrl+break");

                        Signals.SendCtrlBreak(coqtop.Id);
                        using (var y = reader.ReadSubtree())
                        {
                            y.Read();
                            await y.ReadOuterXmlAsync();
                        }
                        //await reader.SkipAsync();
                    }
                    else if (reader.NodeType == XmlNodeType.Element)
                    {
                        using (var y = reader.ReadSubtree())
                        {
                            y.Read();
                            await writer.WriteAsync(await y.ReadOuterXmlAsync());

                            await writer.FlushAsync();
                        }
                    }
                }
            }
            catch (Exception error)
            {
                Console.Error.WriteLine("Error reading main channel write stream.");
                Console.Error.WriteLine("Reason: " + error.ToString());
                System.Environment.Exit(-1);
            }
        }
Exemplo n.º 10
0
        /// <summary>
        /// Load oar control file
        /// </summary>
        /// <param name="path"></param>
        /// <param name="data"></param>
        protected void LoadControlFile(string path, byte[] data)
        {
            XmlNamespaceManager nsmgr   = new XmlNamespaceManager(new NameTable());
            XmlParserContext    context = new XmlParserContext(null, nsmgr, null, XmlSpace.None);
            XmlTextReader       xtr     = new XmlTextReader(Encoding.ASCII.GetString(data), XmlNodeType.Document, context);

            RegionSettings currentRegionSettings = m_scene.RegionInfo.RegionSettings;

            // Loaded metadata will empty if no information exists in the archive
            currentRegionSettings.LoadedCreationDateTime = 0;
            currentRegionSettings.LoadedCreationID       = "";

            while (xtr.Read())
            {
                if (xtr.NodeType == XmlNodeType.Element)
                {
                    if (xtr.Name.ToString() == "archive")
                    {
                        int    majorVersion = int.Parse(xtr["major_version"]);
                        int    minorVersion = int.Parse(xtr["minor_version"]);
                        string version      = string.Format("{0}.{1}", majorVersion, minorVersion);

                        if (majorVersion > MAX_MAJOR_VERSION)
                        {
                            throw new Exception(
                                      string.Format(
                                          "The OAR you are trying to load has major version number of {0} but this version of OpenSim can only load OARs with major version number {1} and below",
                                          majorVersion, MAX_MAJOR_VERSION));
                        }

                        m_log.InfoFormat("[ARCHIVER]: Loading OAR with version {0}", version);
                    }
                    if (xtr.Name.ToString() == "datetime")
                    {
                        int value;
                        if (Int32.TryParse(xtr.ReadElementContentAsString(), out value))
                        {
                            currentRegionSettings.LoadedCreationDateTime = value;
                        }
                    }
                    else if (xtr.Name.ToString() == "id")
                    {
                        currentRegionSettings.LoadedCreationID = xtr.ReadElementContentAsString();
                    }
                }
            }

            currentRegionSettings.Save();
        }
Exemplo n.º 11
0
        public CoqtopXmlReader(StreamReader source)
        {
            var settings = new XmlReaderSettings();

            settings.Async            = true;
            settings.CheckCharacters  = false;
            settings.ValidationType   = ValidationType.None;
            settings.ConformanceLevel = ConformanceLevel.Fragment;
            settings.DtdProcessing    = DtdProcessing.Parse;
            var context = new XmlParserContext(null, new XmlNamespaceManager(new NameTable()), null, XmlSpace.None, Encoding.UTF8);

            context.InternalSubset = "<!ENTITY nbsp \"&#160;\">";
            context.DocTypeName    = "coq";
            this.reader            = XmlTextReader.Create(source, settings, context);
        }
Exemplo n.º 12
0
        }         // func GetXmlStreamAsync

        public XmlReader GetXmlStreamAsync(WebResponse response, string acceptedMimeType = MimeTypes.Text.Xml, XmlReaderSettings settings = null)
        {
            if (settings == null)
            {
                settings = new XmlReaderSettings();
                settings.IgnoreComments   = acceptedMimeType != MimeTypes.Application.Xaml;
                settings.IgnoreWhitespace = acceptedMimeType != MimeTypes.Application.Xaml;
            }
            settings.CloseInput = true;

            var baseUri = response.ResponseUri.GetComponents(UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.SafeUnescaped);
            var context = new XmlParserContext(null, null, null, null, null, null, baseUri, null, XmlSpace.Default);

            return(XmlReader.Create(GetTextReaderAsync(response, acceptedMimeType), settings, context));
        }         // func GetXmlStreamAsync
Exemplo n.º 13
0
        private static XmlReader CreateXmlReader(Stream stream)
        {
            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("v", "http://www.eki.ee/dict/evs");

            XmlParserContext context = new XmlParserContext(null, namespaceManager, null, XmlSpace.None);

            XmlReaderSettings readerSettings = new XmlReaderSettings
            {
                ConformanceLevel = ConformanceLevel.Fragment
            };

            return(XmlReader.Create(stream, readerSettings, context));
        }
Exemplo n.º 14
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="component">Associated editor</param>
 private EdxDocument(XmlControl component)
 {
     this.editor            = component.HtmlEditor;
     this.nativeRootControl = component;
     //prepare the validating reader for accepting HTML characters
     xhtmlContext      = Util.CreateXhtmlContext();
     xs                = new XmlReaderSettings();
     xs.ProhibitDtd    = false;
     xs.ValidationType = ValidationType.None;
     xs.XmlResolver    = Util.CreateXhtmlResolver();
     // Namespace resolver
     xmlnsEdx  = Util.CreateEdxNamespaceManager();
     fo        = new HtmlFormatterOptions(' ', 1, 1024, true);
     formatter = new HtmlFormatter();
 }
Exemplo n.º 15
0
        /// <summary>
        /// Creates the validating XML reader.
        /// </summary>
        /// <param name="uri">The URI.</param>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        private XmlReader CreateValidatingXmlReader(string uri, Stream stream)
        {
            //return new XmlTextReader(uri, stream);
            XmlReaderSettings xmlReaderSettings = GetXmlReaderSettings();

            if (string.IsNullOrWhiteSpace(uri))
            {
                return(XmlReader.Create(stream, xmlReaderSettings, uri));
            }
            else
            {
                XmlParserContext xmlParserContext = GetXmlParserContext();
                return(XmlReader.Create(stream, xmlReaderSettings, xmlParserContext));
            }
        }
Exemplo n.º 16
0
        private static XmlNode getXmlNodeFromString(String str, XmlDocument dest)
        {
            XmlNode result = null;
            //Костыль, позволяющий избежать ошибки необъявленного нэймспейса xs в открываемых паттернах
            XmlNamespaceManager mgr = new XmlNamespaceManager(new NameTable());

            mgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
            XmlParserContext ctx = new XmlParserContext(null, mgr, null, XmlSpace.Default);

            using (XmlReader reader = XmlReader.Create(new StringReader(str), null, ctx))
            {
                result = dest.ReadNode(reader);
            }
            return(result);
        }
Exemplo n.º 17
0
        public ILogEventParserInstance Begin(Stream stream)
        {
            //
            // a trick to handle multiple-root xml streams
            // as described by Oleg Tkachenko in his blog:
            //
            // http://www.tkachenko.com/blog/archives/000053.html
            //

            XmlParserContext context = new XmlParserContext(new NameTable(), null, null, XmlSpace.Default);
            XmlTextReader    xtr     = new XmlTextReader(stream, XmlNodeType.Element, context);

            xtr.Namespaces = false;
            return(new Context(xtr));
        }
Exemplo n.º 18
0
        /// <summary>
        /// Получить содержимое блока в виде xml.
        /// </summary>
        /// <param name="blockName">Имя блока.</param>
        /// <returns>Содержимым блока.</returns>
        public XElement GetXmlBlockContent(string blockName)
        {
            var content = this.GetBlockContent(blockName);

            if (string.IsNullOrEmpty(content))
            {
                return(null);
            }

            var namespaceManager = new XmlNamespaceManager(new NameTable());
            var parserContext    = new XmlParserContext(null, namespaceManager, null, XmlSpace.Preserve);

            using (var xmlReader = new XmlTextReader(content, XmlNodeType.Element, parserContext))
                return(XElement.Load(xmlReader));
        }
Exemplo n.º 19
0
        public static Node FromXmlFragment(string xml, IssueSink sink)
        {
            NameTable nt = new NameTable();

            XmlNamespaceManager nsmanager = new XmlNamespaceManager(nt);
            XmlParserContext    context   =
                new XmlParserContext(nt, nsmanager, "elem", XmlSpace.None, System.Text.Encoding.UTF8);
            XmlTextReader reader = new XmlTextReader(xml, XmlNodeType.Element, context);


            Node n = new Node(new XmlDocument().ReadNode(reader) as XmlElement, sink);

            reader.Close();
            return(n);
        }
Exemplo n.º 20
0
        /// <summary>
        /// Static constructior to initialize the Log4J XML parser context.
        /// </summary>
        static LogMessageLog4Net()
        {
            XmlNamespaceManager namespaceManager =
                new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace(
                "log4j"
                , "http://jakarta.apache.org/log4j/");

            mParserContext = new XmlParserContext(
                null
                , namespaceManager
                , null
                , XmlSpace.Default);
        }
Exemplo n.º 21
0
    public static XDocument ParseDocument(string diagramXml)
    {
        XmlNamespaceManager nmgr = new XmlNamespaceManager(new NameTable());

        nmgr.AddNamespace("xsi", WorkflowBuilder.xsi.NamespaceName);
        nmgr.AddNamespace("bpmn", WorkflowBuilder.bpmn.NamespaceName);
        nmgr.AddNamespace("bpmndi", WorkflowBuilder.bpmndi.NamespaceName);
        nmgr.AddNamespace("dc", WorkflowBuilder.dc.NamespaceName);
        nmgr.AddNamespace("di", WorkflowBuilder.di.NamespaceName);

        XmlParserContext pctx   = new XmlParserContext(null, nmgr, null, XmlSpace.None);
        XmlTextReader    reader = new XmlTextReader(diagramXml, XmlNodeType.Document, pctx);

        return(XDocument.Load(reader));
    }
Exemplo n.º 22
0
        public XmlReaderBodyWriter(string xml, int maxBufferSize, XmlParserContext ctx)
            : base(true)
        {
            var settings = new XmlReaderSettings()
            {
                // FIXME: enable this line (once MaxCharactersInDocument is implemented)
                // MaxCharactersInDocument = maxBufferSize,
                ConformanceLevel = ConformanceLevel.Fragment
            };

            reader = XmlDictionaryReader.CreateDictionaryReader(XmlReader.Create(new StringReader(xml), settings, ctx));
            reader.MoveToContent();
            xml_bak        = xml;
            parser_context = ctx;
        }
Exemplo n.º 23
0
        private async Task <SpatialDataSet> ParseGPX(Stream gpxStream)
        {
            var nt    = new NameTable();
            var nsmgr = new XmlNamespaceManager(nt);

            nsmgr.AddNamespace("gpxx", GpxxNamespace);

            var pc = new XmlParserContext(null, nsmgr, null, XmlSpace.None);

            using (var reader = XmlReader.Create(gpxStream, null, pc))
            {
                var doc = XDocument.Load(reader);
                return(await ParseGPX(doc, string.Empty));
            }
        }
Exemplo n.º 24
0
        private bool Populate(string data)
        {
            XElement element;
            int      lineNumber;

            if (!_validQueryHeader.IsMatch(data))
            {
                return(false);
            }
            try
            {
                XmlParserContext context     = new XmlParserContext(null, null, null, XmlSpace.None);
                Stream           xmlFragment = new MemoryStream(Encoding.UTF8.GetBytes(data));
                XmlTextReader    reader      = new XmlTextReader(xmlFragment, XmlNodeType.Element, context);
                reader.MoveToContent();
                XmlReader     reader2 = reader.ReadSubtree();
                StringBuilder output  = new StringBuilder();
                using (XmlWriter writer = XmlWriter.Create(output))
                {
                    writer.WriteNode(reader2, true);
                }
                element    = XElement.Parse(output.ToString());
                lineNumber = reader.LineNumber;
            }
            catch (XmlException)
            {
                return(false);
            }
            if (element.Attribute("Kind") != null)
            {
                try
                {
                    this._language = (QueryLanguage)Enum.Parse(typeof(QueryLanguage), (string)element.Attribute("Kind"), true);
                }
                catch (ArgumentException)
                {
                }
            }
            this._metaData = element;
            StringReader reader3 = new StringReader(data);

            for (int i = 0; i < lineNumber; i++)
            {
                reader3.ReadLine();
            }
            this._text = reader3.ReadToEnd().Trim();
            return(true);
        }
Exemplo n.º 25
0
        public static string LimitHtmlOnWordBoundary(this string str, int maxLength, string ellipses = "...")
        {
            XmlDocument doc = new XmlDocument();

            XmlParserContext context = new XmlParserContext(doc.NameTable, new XmlNamespaceManager(doc.NameTable), null, XmlSpace.Preserve);
            XmlTextReader    reader  = new XmlTextReader("<xml>" + str + "</xml>", XmlNodeType.Document, context);
            bool             shouldWriteEllipses;

            using (var writer = doc.CreateNavigator().AppendChild())
            {
                LimitHtmlOnWordBoundary(writer, reader, maxLength, out shouldWriteEllipses);
                writer.Flush();
            }

            return(doc.DocumentElement.InnerXml + (shouldWriteEllipses ? ellipses : ""));
        }
Exemplo n.º 26
0
        public void Parse3()
        {
            XmlNamespaceManager nsMgr         = new MyNS(XmlReader.Create(new StringReader(empty)));
            XmlParserContext    inputContext  = new XmlParserContext(null, nsMgr, null, XmlSpace.None);
            XmlReader           xr            = XmlReader.Create(new StringReader(xmlstr), new XmlReaderSettings(), inputContext);
            XmlNamespaceManager aMgr          = new MyNS(xr);
            XmlParserContext    inputContext2 = new XmlParserContext(null, aMgr, null, XmlSpace.None);

            XmlReader xr2 = XmlReader.Create(new StringReader(xmlstr2), new XmlReaderSettings(), inputContext2);

            Assert.Throws <XmlException> (delegate {
                while (xr2.Read())
                {
                }
            }, "null");
        }
Exemplo n.º 27
0
        public void Parse2()
        {
            XmlNamespaceManager nsMgr = new MyNS(XmlReader.Create(new StringReader(empty)));

            nsMgr.AddNamespace("foo", "bar");
            XmlParserContext    inputContext  = new XmlParserContext(null, nsMgr, null, XmlSpace.None);
            XmlReader           xr            = XmlReader.Create(new StringReader(xmlstr), new XmlReaderSettings(), inputContext);
            XmlNamespaceManager aMgr          = new MyNS(xr);
            XmlParserContext    inputContext2 = new XmlParserContext(null, aMgr, null, XmlSpace.None);

            XmlReader xr2 = XmlReader.Create(new StringReader(xmlstr2), new XmlReaderSettings(), inputContext2);

            while (xr2.Read())
            {
            }
        }
Exemplo n.º 28
0
        private string NfeDadosMsg(string sJust)
        {
            XmlSchemaCollection myschema = new XmlSchemaCollection();
            XmlValidatingReader reader;

            try
            {
                DataTable dt = BuscaProtocoloNFe(objPesquisa.sCD_NFSEQ);


                XNamespace xname = "http://www.portalfiscal.inf.br/nfe";
                XDocument  xdoc  = new XDocument(new XElement(xname + "cancNFe", new XAttribute("versao", Acesso.versaoNFe),
                                                              new XElement(xname + "infCanc", new XAttribute("Id", "ID" + objPesquisa.sCHAVENFE),
                                                                           new XElement(xname + "tpAmb", Acesso.TP_AMB),
                                                                           new XElement(xname + "xServ", "CANCELAR"),
                                                                           new XElement(xname + "chNFe", objPesquisa.sCHAVENFE),
                                                                           new XElement(xname + "nProt", dt.Rows[0]["cd_nprotnfe"].ToString()),
                                                                           new XElement(xname + "xJust", sJust))));
                string sPath = Pastas.PROTOCOLOS + "\\" + objPesquisa.sCD_NFSEQ + "_ped-can.xml";
                xdoc.Save(sPath);

                belAssinaXml assinaCanc       = new belAssinaXml();
                string       sArquivoAssinado = assinaCanc.ConfigurarArquivo(sPath, "infCanc", Acesso.cert_NFe);

                StreamReader ler;
                ler = File.OpenText(sPath);

                XmlParserContext context = new XmlParserContext(null, null, "", XmlSpace.None);

                reader = new XmlValidatingReader(ler.ReadToEnd().ToString(), XmlNodeType.Element, context);

                myschema.Add("http://www.portalfiscal.inf.br/nfe", Pastas.SCHEMA_NFE + "\\cancNFe_v2.00.xsd");

                reader.ValidationType = ValidationType.Schema;

                reader.Schemas.Add(myschema);

                while (reader.Read())
                {
                }
                return(sArquivoAssinado);
            }
            catch (Exception x)
            {
                throw new Exception(x.Message);
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// Checks the update via RSS.
        /// </summary>
        /// <param name="uri">The URI.</param>
        private void CheckUpdateViaRss(Uri uri)
        {
            _updateList = new UpdateInfoList();
            XmlDocument doc = new XmlDocument();

            try {
                Stream strm = GetRssStream(uri);
                using ( strm ) {
                    doc.Load(strm);
                }
            } catch { throw; }
            XmlNamespaceManager nsm = CreateXmlNamespaceManager(doc);

            XmlNodeList updateInfoNodes = doc.SelectNodes(string.Format(Properties.Strings.UpdateInfoRootXPath, Properties.Strings.UpdateInfoNamespacePrefix), nsm);

            // Console.WriteLine ( "{0} Update info items found", updateInfoNodes.Count );

            foreach (XmlElement uie in updateInfoNodes)
            {
                try {
                    XmlParserContext xpc    = new XmlParserContext(doc.NameTable, nsm, string.Empty, XmlSpace.Preserve);
                    XmlTextReader    reader = new XmlTextReader(uie.OuterXml, XmlNodeType.Element, xpc);

                    XmlSerializer serializer = new XmlSerializer(typeof(UpdateInfo), nsm.LookupNamespace(Properties.Strings.UpdateInfoNamespacePrefix));
                    _updateList.Add(serializer.Deserialize(reader) as UpdateInfo);
                } catch (Exception ex) {
                    Console.WriteLine(ex.ToString());
                }
            }

            _updateList.Sort(new UpdateInfoVersionComparer());
            if (_updateList.Count > 0)
            {
                UpdateInfo _updateInfo = UpdateInfoList[UpdateInfoList.GetLatestVersion(  )];
                foreach (UpdateFile uf in _updateInfo.Files)
                {
                    if (uf.Version.CompareTo(this.Version) > 0)
                    {
                        _updatesAvailable = true;
                    }
                }
                if (_updatesAvailable || _updateInfo.Version.CompareTo(this.Version) > 0)
                {
                    OnUpdateAvailable(new UpdatesAvailableEventArgs(_updateInfo.Version));
                }
            }
        }
Exemplo n.º 30
0
        private List <ValidationResult> ValidateSchema(string fileName, ValidationProfile profile, byte[] sourceData, XmlNamespaceManager nsManager)
        {
            Dictionary <string, string> namespaces = null;
            XmlSchemaCollection         schemas    = new XmlSchemaCollection();

            schemas.Add(Helper.GetSchema(profile.SchemaLocation, out namespaces));

            XmlParserContext context = new XmlParserContext(null, nsManager, null, XmlSpace.None);

            using (MemoryStream sourceStream = new MemoryStream(sourceData))
            {
                XmlValidatingReader validatingReader = new XmlValidatingReader(sourceStream, XmlNodeType.Document, context);
                validatingReader.ValidationType = ValidationType.Schema;
                validatingReader.Schemas.Add(schemas);

                List <ValidationResult> results   = new List <ValidationResult>();
                ValidationResult        newResult = null;

                validatingReader.ValidationEventHandler += new ValidationEventHandler(delegate(object sender, ValidationEventArgs e)
                {
                    newResult = new ValidationResult()
                    {
                        FileName     = fileName,
                        ErrorMessage = e.Message,
                        Severity     = e.Severity.ToString(),
                        TestContext  = "Schema",
                        Test         = "N/A",
                        Location     = "N/A",
                        LineNumber   = e.Exception.LineNumber
                    };

                    results.Add(newResult);
                });

                while (validatingReader.Read())
                {
                    if (newResult != null)
                    {
                        newResult.Test = validatingReader.Name;
                        results.Add(newResult);
                        newResult = null;
                    }
                }

                return(results);
            }
        }
Exemplo n.º 31
0
 /// <summary>
 /// Implements the following function
 /// node-set exsl:node-set(object)
 /// </summary>
 /// <param name="o"></param>
 /// <returns></returns>
 public XPathNodeIterator nodeSet(object o)
 {
     if (o is XPathNavigator)
     {
         XPathNavigator nav = (XPathNavigator)o;
         if (selectItself == null)
         {
             selectItself = nav.Compile(".");
         }
         return(nav.Select(selectItself.Clone()));
     }
     else if (o is XPathNodeIterator)
     {
         return(o as XPathNodeIterator);
     }
     else
     {
         string s;
         if (o is string)
         {
             s = o as string;
         }
         else if (o is bool)
         {
             s = ((bool)o)? "true" : "false";
         }
         else if (o is Double || o is Int16 || o is UInt16 || o is Int32 ||
                  o is UInt32 || o is Int64 || o is UInt64 || o is Single || o is Decimal)
         {
             s = o.ToString();
         }
         else
         {
             return(null);
         }
         //Now convert it to text node
         XmlParserContext context = new XmlParserContext(null, null, null, XmlSpace.None);
         XPathDocument    doc     = new XPathDocument(
             new XmlTextReader("<d>" + s + "</d>", XmlNodeType.Element, context));
         XPathNavigator nav = doc.CreateNavigator();
         if (selectText == null)
         {
             selectText = nav.Compile("/d/text()");
         }
         return(nav.Select(selectText.Clone()));
     }
 }
Exemplo n.º 32
0
        /// <summary>Converts an <see cref="T:System.Windows.Markup.ParserContext" /> to an <see cref="T:System.Xml.XmlParserContext" />.</summary>
        /// <param name="parserContext">The context to convert to an <see cref="T:System.Xml.XmlParserContext" />.</param>
        /// <returns>The XML parser context.</returns>
        /// <exception cref="T:System.ArgumentNullException">
        ///         <paramref name="parserContext" /> is <see langword="null" />.</exception>
        // Token: 0x060021E5 RID: 8677 RVA: 0x000A98C4 File Offset: 0x000A7AC4
        public static XmlParserContext ToXmlParserContext(ParserContext parserContext)
        {
            if (parserContext == null)
            {
                throw new ArgumentNullException("parserContext");
            }
            XmlNamespaceManager xmlNamespaceManager = new XmlNamespaceManager(new NameTable());
            XmlSpace            xmlSpace            = System.Xml.XmlSpace.None;

            if (parserContext.XmlSpace != null && parserContext.XmlSpace.Length != 0)
            {
                TypeConverter converter = TypeDescriptor.GetConverter(typeof(XmlSpace));
                if (converter != null)
                {
                    try
                    {
                        xmlSpace = (XmlSpace)converter.ConvertFromString(null, TypeConverterHelper.InvariantEnglishUS, parserContext.XmlSpace);
                    }
                    catch (FormatException)
                    {
                        xmlSpace = System.Xml.XmlSpace.None;
                    }
                }
            }
            if (parserContext._xmlnsDictionary != null)
            {
                foreach (object obj in parserContext._xmlnsDictionary.Keys)
                {
                    string prefix = (string)obj;
                    xmlNamespaceManager.AddNamespace(prefix, parserContext._xmlnsDictionary[prefix]);
                }
            }
            XmlParserContext xmlParserContext = new XmlParserContext(null, xmlNamespaceManager, parserContext.XmlLang, xmlSpace);

            if (parserContext.BaseUri == null)
            {
                xmlParserContext.BaseURI = null;
            }
            else
            {
                string components  = parserContext.BaseUri.GetComponents(UriComponents.SerializationInfoString, UriFormat.SafeUnescaped);
                Uri    uri         = new Uri(components);
                string components2 = uri.GetComponents(UriComponents.SerializationInfoString, UriFormat.UriEscaped);
                xmlParserContext.BaseURI = components2;
            }
            return(xmlParserContext);
        }
	// Test parser context creation.
	public void TestXmlParserContextConstruct()
			{
				NameTable nt = new NameTable();
				NameTable nt2 = new NameTable();
				XmlNamespaceManager ns = new XmlNamespaceManager(nt);
				XmlParserContext ctx;

				// Try to construct with the wrong name table.
				try
				{
					ctx = new XmlParserContext(nt2, ns, null, XmlSpace.None);
					Fail("Construct (1)");
				}
				catch(XmlException)
				{
					// Success
				}

				// Check default property values.
				ctx = new XmlParserContext(null, ns, null, XmlSpace.None);
				AssertEquals("Construct (2)", "", ctx.BaseURI);
				AssertEquals("Construct (3)", "", ctx.DocTypeName);
				AssertEquals("Construct (4)", null, ctx.Encoding);
				AssertEquals("Construct (5)", "", ctx.InternalSubset);
				AssertEquals("Construct (6)", nt, ctx.NameTable);
				AssertEquals("Construct (7)", ns, ctx.NamespaceManager);
				AssertEquals("Construct (8)", "", ctx.PublicId);
				AssertEquals("Construct (9)", "", ctx.SystemId);
				AssertEquals("Construct (10)", "", ctx.XmlLang);
				AssertEquals("Construct (11)", XmlSpace.None, ctx.XmlSpace);

				// Check overridden property values.
				ctx = new XmlParserContext(nt, null, "doctype",
										   "pubid", "sysid", "internal",
										   "base", "lang", XmlSpace.Preserve,
										   Encoding.UTF8);
				AssertEquals("Construct (12)", "base", ctx.BaseURI);
				AssertEquals("Construct (13)", "doctype", ctx.DocTypeName);
				AssertEquals("Construct (14)", Encoding.UTF8, ctx.Encoding);
				AssertEquals("Construct (15)", "internal", ctx.InternalSubset);
				AssertEquals("Construct (16)", nt, ctx.NameTable);
				AssertEquals("Construct (17)", null, ctx.NamespaceManager);
				AssertEquals("Construct (18)", "pubid", ctx.PublicId);
				AssertEquals("Construct (19)", "sysid", ctx.SystemId);
				AssertEquals("Construct (20)", "lang", ctx.XmlLang);
				AssertEquals("Construct (21)", XmlSpace.Preserve, ctx.XmlSpace);
			}
 public static XmlReader Create(string inputUri, XmlReaderSettings settings, XmlParserContext inputContext)
 {
 }
 public XmlTextReader(string xmlFragment, XmlNodeType fragType, XmlParserContext context)
 {
 }
 public XmlTextReader(System.IO.Stream xmlFragment, XmlNodeType fragType, XmlParserContext context)
 {
 }
	// Test parser context property changes.
	public void TestXmlParserContextProperties()
			{
				NameTable nt = new NameTable();
				NameTable nt2 = new NameTable();
				XmlNamespaceManager ns = new XmlNamespaceManager(nt);
				XmlParserContext ctx = new XmlParserContext
					(nt, ns, null, XmlSpace.None);

				// Set and check the various properties.
				ctx.BaseURI = "xyzzy";
				AssertEquals("BaseURI (1)", "xyzzy", ctx.BaseURI);
				ctx.BaseURI = null;
				AssertEquals("BaseURI (2)", "", ctx.BaseURI);

				ctx.DocTypeName = "xyzzy";
				AssertEquals("DocTypeName (1)", "xyzzy", ctx.DocTypeName);
				ctx.DocTypeName = null;
				AssertEquals("DocTypeName (2)", "", ctx.DocTypeName);

				ctx.Encoding = Encoding.UTF8;
				AssertEquals("Encoding (1)", Encoding.UTF8, ctx.Encoding);
				ctx.Encoding = null;
				AssertEquals("Encoding (2)", null, ctx.Encoding);

				ctx.InternalSubset = "xyzzy";
				AssertEquals("InternalSubset (1)", "xyzzy", ctx.InternalSubset);
				ctx.InternalSubset = null;
				AssertEquals("InternalSubset (2)", "", ctx.InternalSubset);

				ctx.NameTable = nt2;
				AssertEquals("NameTable (1)", nt2, ctx.NameTable);
				ctx.NameTable = null;
				AssertEquals("NameTable (2)", null, ctx.NameTable);

				ctx.NamespaceManager = null;
				AssertEquals("NamespaceManager (1)", null,
							 ctx.NamespaceManager);
				ctx.NamespaceManager = ns;
				AssertEquals("NamespaceManager (2)", ns, ctx.NamespaceManager);

				ctx.PublicId = "xyzzy";
				AssertEquals("PublicId (1)", "xyzzy", ctx.PublicId);
				ctx.PublicId = null;
				AssertEquals("PublicId (2)", "", ctx.PublicId);

				ctx.SystemId = "xyzzy";
				AssertEquals("SystemId (1)", "xyzzy", ctx.SystemId);
				ctx.SystemId = null;
				AssertEquals("PublicId (2)", "", ctx.SystemId);

				ctx.XmlLang = "xyzzy";
				AssertEquals("XmlLang (1)", "xyzzy", ctx.XmlLang);
				ctx.XmlLang = null;
				AssertEquals("XmlLang (2)", "", ctx.XmlLang);

				ctx.XmlSpace = XmlSpace.Default;
				AssertEquals("XmlSpace (1)", XmlSpace.Default, ctx.XmlSpace);
				ctx.XmlSpace = XmlSpace.None;
				AssertEquals("XmlSpace (2)", XmlSpace.None, ctx.XmlSpace);
			}
 public static XmlReader Create(TextReader input, XmlReaderSettings settings, XmlParserContext inputContext);
 public static XmlReader Create(System.IO.TextReader input, XmlReaderSettings settings, XmlParserContext inputContext)
 {
 }
Exemplo n.º 40
0
        private XmlReader CreateContextReader(string xml, bool fromCurrentNode)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }

            // We have to set the namespace context for the reader.
            XPathNavigator editor = CreateNavigator();
            // scope starts from parent.
            XmlNamespaceManager mgr = new XmlNamespaceManager(NameTable);
            if (!fromCurrentNode)
            {
                editor.MoveToParent(); // should always succeed.
            }
            if (editor.MoveToFirstNamespace(XPathNamespaceScope.All))
            {
                do
                {
                    mgr.AddNamespace(editor.LocalName, editor.Value);
                }
                while (editor.MoveToNextNamespace(XPathNamespaceScope.All));
            }

            XmlParserContext context = new XmlParserContext(NameTable, mgr, null, XmlSpace.Default);
            return XmlReader.Create(new StringReader(xml), new XmlReaderSettings(), context);
        }
Exemplo n.º 41
0
 public XmlParserContext GetParserContext()
 {
     NameTable nt = new NameTable();
     XmlParserContext pc = new XmlParserContext(nt, new XmlNamespaceManager(nt), null, XmlSpace.Default);
     return pc;
 }
Exemplo n.º 42
0
 public static bool Create(String url, XmlReaderSettings settings, XmlParserContext context)
 {
     XmlReader reader = null;
     try
     {
         reader = ReaderHelper.Create(url, settings, context);
         while (reader.Read()) ;
         return true;
     }
     catch (ArgumentNullException ane)
     {
         CError.WriteLineIgnore(ane.ToString());
         return false;
     }
     finally
     {
         if (reader != null)
             reader.Dispose();
     }
 }