コード例 #1
0
        public static XmlElementInfo GetInfo(XmlReader xmlReader, XmlElementInfo parent)
        {
            XmlElementInfo info = GetInfo(xmlReader);

            info.Parent = parent;
            return(info);
        }
コード例 #2
0
        public static XmlElementInfo GetInfo(XmlReader xmlReader)
        {
            XmlElementInfo info = new XmlElementInfo(xmlReader.NamespaceURI, xmlReader.Prefix, xmlReader.LocalName,
                                                     xmlReader.Depth);

            return(info);
        }
コード例 #3
0
ファイル: Space.cs プロジェクト: daliboris/ITJakub
 /// <summary>
 /// Initializes a new instance of the <see cref="T:System.Object"/> class.
 /// </summary>
 public Space(bool spaceAsAttribute, XmlElementInfo currentTag)
 {
     Depth              = currentTag.Depth;
     SpaceAsAttribute   = spaceAsAttribute;
     CurrentTag         = currentTag.Name;
     CurrentElementInfo = currentTag;
 }
コード例 #4
0
ファイル: Space.cs プロジェクト: daliboris/ITJakub
 public Space(string text, XmlElementInfo currentTag)
 {
     Text               = text;
     Depth              = currentTag.Depth;
     CurrentTag         = currentTag.Name;
     CurrentElementInfo = currentTag;
 }
コード例 #5
0
 public XmlElementInfo(string ns, string prefix, string name, int depth, XmlElementInfo parent)
 {
     Namespace = ns;
     Prefix    = prefix;
     Name      = name;
     Depth     = depth;
     Parent    = parent;
 }
コード例 #6
0
ファイル: WordBreaker.cs プロジェクト: daliboris/ITJakub
        private void WriteXmlElementInfo(XmlElementInfo xmlElementInfo)
        {
            return;

            if (xmlElementInfo != null)
            {
                // ReSharper disable LocalizableElement
                Console.WriteLine("{0}, {1}, {2}, {3}", xmlElementInfo.Name, xmlElementInfo.Prefix, xmlElementInfo.Depth, xmlElementInfo.GetXPath());
            }
            // ReSharper restore LocalizableElement
        }
コード例 #7
0
ファイル: WordBreaker.cs プロジェクト: daliboris/ITJakub
        public void Run()
        {
            int id = 0;

            XmlElementInfo currentElement = null;

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

            namespaceManager.AddNamespace(String.Empty, NsTei);

            XmlWriterSettings xmlWriterSettings = new XmlWriterSettings();

            xmlWriterSettings.Indent = true;

            List <string>  ignoredElements = IgnoredElements ?? new List <string>();
            XmlElementInfo ignoredElement  = null;

            string punctation = Punctation ?? String.Empty;

            bool ignoreText = false;
            bool?isRoot     = null;

            using (XmlReader xmlReader = XmlReader.Create(Input))
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(Output, xmlWriterSettings))
                {
                    xmlWriter.WriteStartDocument();


                    while (xmlReader.Read())
                    {
                        XmlNodeType nodeType = xmlReader.NodeType;
                        if (nodeType == XmlNodeType.Element)
                        {
                            if (!xmlReader.IsEmptyElement)
                            {
                                currentElement = XmlElementInfo.GetInfo(xmlReader, currentElement);
                            }
                            WriteXmlElementInfo(currentElement);

                            isRoot = !isRoot.HasValue;
                            if (ignoredElement == null && ignoredElements.Contains(xmlReader.LocalName))
                            {
                                ignoredElement = currentElement;
                                ignoreText     = true;
                            }
                        }
                        if (nodeType == XmlNodeType.EndElement)
                        {
                            if (currentElement != null &&
                                ignoreText &&
                                currentElement.Name == ignoredElement.Name &&
                                currentElement.Depth == ignoredElement.Depth)
                            //if (ignoredElements.Contains(xmlReader.LocalName))
                            {
                                ignoredElement = null;
                                ignoreText     = false;
                            }
                            if (currentElement != null)
                            {
                                currentElement = currentElement.Parent;
                            }
                            WriteXmlElementInfo(currentElement);
                        }
                        if (nodeType == XmlNodeType.Text)
                        {
                            if (ignoreText)
                            {
                                Transformace.SerializeNode(xmlReader, xmlWriter);
                                continue;
                            }


                            string text = xmlReader.Value;

                            if (text.IndexOf(' ') == -1)
                            {
                                xmlWriter.WriteElementString("w", NsTei, text);
                            }
                            else
                            {
                                _capacity = text.Length;
                                StringBuilder stringBuilder = new StringBuilder(_capacity);
                                foreach (char c in text)
                                {
                                    if (c == ' ' || c == '\u0001' || c == '\t') //mezera a pevná mezera
                                    {
                                        WriteWordElement(ref stringBuilder, xmlWriter, _capacity, id++, XmlIdFormat);
                                        xmlWriter.WriteStartElement("c");
                                        xmlWriter.WriteAttributeString("type", "space");
                                        xmlWriter.WriteAttributeString("space", NsXml, "preserve");
                                        if (c == '\t')
                                        {
                                            xmlWriter.WriteString("\t");
                                        }
                                        else
                                        {
                                            xmlWriter.WriteString(" ");
                                        }
                                        xmlWriter.WriteEndElement();
                                    }
                                    else
                                    {
                                        if (punctation.IndexOf(c) > -1)
                                        {
                                            WriteWordElement(ref stringBuilder, xmlWriter, _capacity, id++, XmlIdFormat);
                                            xmlWriter.WriteElementString("pc", NsTei, String.Format("{0}", c));
                                        }
                                        else
                                        {
                                            stringBuilder.Append(c);
                                        }
                                    }
                                }
                                //výpis posledního slova uloženého v bufferu
                                WriteWordElement(ref stringBuilder, xmlWriter, 0, id++, XmlIdFormat);
                            }
                        }
                        else
                        {
                            Transformace.SerializeNode(xmlReader, xmlWriter);
                            if (isRoot.HasValue && isRoot.Value)
                            {
                                xmlWriter.WriteAttributeString("xmlns", "nlp", null, NsNlp);
                                isRoot = false;
                            }
                        }
                    }
                }
            }
        }
コード例 #8
0
 public XmlElementInfo(string name, int depth, XmlElementInfo parent)
 {
     Name   = name;
     Depth  = depth;
     Parent = parent;
 }