Exemplo n.º 1
0
        private string ZjistiGrantovouPodporu(string souborDocx)
        {
            string result = null;

            if (!File.Exists(souborDocx))
            {
                return(result);
            }
            string sTempXml = Path.GetTempFileName();

            //OOXML.Pomucky.Dokument.ExtrahovatDoSouboru(sSouborDocx, sTempXml, true);
            OOXML.Pomucky.Dokument.ExtrahovatDoSouboru(souborDocx, sTempXml, false);
            XmlReaderSettings xrs = new XmlReaderSettings();

            xrs.CloseInput       = true;
            xrs.ConformanceLevel = ConformanceLevel.Document;
            XmlReader xr = XmlReader.Create(sTempXml, xrs);

            XmlNamespaceManager namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("w", "http://schemas.openxmlformats.org/wordprocessingml/2006/main");
            try
            {
                while (xr.Read())
                {
                    if (xr.NodeType == XmlNodeType.Element)
                    {
                        switch (xr.Name)
                        {
                        case "w:p":
                            XmlDocument paragraph = Objekty.ReadNodeAsXmlDocument(xr);
                            XmlNode     node      = paragraph.SelectSingleNode("/w:p/w:pPr/w:pStyle", namespaceManager);
                            if (node != null && node.Attributes.Count > 0 &&
                                (node.Attributes["w:val"].Value == "Grantovapodpora" || node.Attributes["w:val"].Value == "Grantova_podpora"))
                            {
                                result = paragraph.InnerText;
                                xr.Close();
                                goto End;
                            }
                            break;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                xr.Close();
                File.Delete(sTempXml);
            }
End:
            if (File.Exists(sTempXml))
            {
                File.Delete(sTempXml);
            }
            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Uloží termíny do samostatného souboru, odstraní prázdné xmlns, pouze s jedinečnými identifikátory
        /// </summary>
        public void TestExtrahujTerminy(string inputFile, string outputFile)
        {
            var xws = new XmlWriterSettings();
            var namespaceManager = new XmlNamespaceManager(new NameTable());

            namespaceManager.AddNamespace("", "http://vokabular.ujc.cas.cz/ns/anotace");

            xws.Indent = true;
            var           identifikatory = new Dictionary <string, string>(10000);
            List <string> heslaPaginy    = null;

            using (var xw = XmlWriter.Create(outputFile, xws))
            {
                xw.WriteStartDocument();
                xw.WriteStartElement("terms");

                using (var xr = XmlReader.Create(inputFile))
                {
                    xr.MoveToContent();
Dalsi:
                    while (xr.Read())
                    {
                        if (xr.NodeType == XmlNodeType.Element && xr.Name == "term")
                        {
                            var guid = xr.GetAttribute("id");
                            if (!identifikatory.ContainsKey(guid))
                            {
                                identifikatory.Add(guid, guid);
                                xr.MoveToElement();
                                var xd = Objekty.ReadNodeAsXmlDocument(xr);
                                xd.DocumentElement.RemoveAttribute("xmlns", "");
                                xw.WriteNode(xd.DocumentElement.CreateNavigator(), false);
                                goto Dalsi;
                                //xw.WriteNode(xr, false);
                            }
                        }
                    }
                }
                xw.WriteEndElement(); //terms
                xw.WriteEndDocument();
            }
        }
Exemplo n.º 3
0
        public CleaningResult Clean(string document)
        {
            CleaningResult result = new CleaningResult();

            string temp = Path.GetTempFileName();

            bool zpracovat = true;

            Queue <RunObject> runs = new Queue <RunObject>();

            RunObject previous = null;

            using (xmlReader = XmlReader.Create(document))
            {
                XmlNamespaceManager nsmgr = new XmlNamespaceManager(xmlReader.NameTable);

                nsmgr.AddNamespace("w", Pomucky.Dokument.RelWordprocessingRelationshipTypeW);

                using (xmlWriter = XmlWriter.Create(temp))
                {
                    xmlWriter.WriteStartDocument();

                    while (xmlReader.Read())
                    {
                        string nazev = xmlReader.Name;
Zacatek:
                        if (xmlReader.NodeType == XmlNodeType.Element)
                        {
                            if (!zpracovat)
                            {
                                break;
                            }
                            switch (nazev)
                            {
                            case "w:r":
                                RunObject   actual = new RunObject();
                                XmlDocument xd     = Objekty.ReadNodeAsXmlDocument(xmlReader);
                                actual.Xml = xd;
                                XmlNode node = xd.SelectSingleNode("/w:r/w:rPr[1]/w:rStyle/@w:val", nsmgr);
                                if (node == null)
                                {
                                    actual.Style = "Standardní písmo odstavce";
                                }
                                else
                                {
                                    actual.Style = node.Value;
                                }
                                XmlNode actualT = actual.Xml.SelectSingleNode("/w:r/w:t[1]", nsmgr);
                                if (actualT == null)                                         //jde o případy obrázku v dokumentu
                                {
                                    if (previous != null)
                                    {
                                        previous.Xml.Save(xmlWriter);
                                    }
                                    actual.Xml.Save(xmlWriter);
                                    actual = previous = null;
                                }
                                if (previous != null)
                                {
                                    if (previous.Style == actual.Style)
                                    {
                                        XmlNode prevT = previous.Xml.SelectSingleNode("/w:r/w:t[1]", nsmgr);
                                        prevT.InnerText += actualT.InnerText;
                                        if (prevT.InnerText[prevT.InnerText.Length - 1] == ' ' && prevT.Attributes["xml:space"] == null)
                                        {
                                            XmlAttribute at = previous.Xml.CreateAttribute("xml", "space", Objekty.XmlNamespace);
                                            at.Value = "preserve";
                                            prevT.Attributes.Append(at);
                                        }
                                        result.NumerOfChanges++;
                                    }
                                    else
                                    {
                                        previous.Xml.Save(xmlWriter);
                                        previous = actual;
                                    }
                                }
                                else
                                {
                                    previous = actual;
                                }
                                goto Zacatek;

                            default:
                                Transformace.SerializeNode(xmlReader, xmlWriter);
                                break;
                            }
                        }
                        else if (xmlReader.NodeType == XmlNodeType.EndElement)
                        {
                            if (nazev == "w:p")
                            {
                                if (previous != null)
                                {
                                    previous.Xml.Save(xmlWriter);
                                }
                                previous = null;
                            }
                            Transformace.SerializeNode(xmlReader, xmlWriter);
                        }
                        else
                        {
                            Transformace.SerializeNode(xmlReader, xmlWriter);
                        }
                    }

                    xmlWriter.WriteEndDocument();
                    xmlWriter.Close();
                }
            }

            result.Output  = temp;
            result.Success = true;
            return(result);
        }