Пример #1
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.LoadXml(xmlStartTag);

            XmlNode nodeStart = xmlDoc.DocumentElement;

            if (nodeStart != null)
            {
                if (nodeStart.HasChildNodes)
                {
                    foreach (XmlNode childNode in nodeStart.ChildNodes)
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, childNode.InnerText));
                        }
                        else if (childNode.Name == "ws")
                        {
                            if (childNode.Attributes.Count == 1)
                            {
                                XmlNode nodeCnt = childNode.Attributes.GetNamedItem("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.InnerText)));
                                }
                            }
                        }
                        else if (childNode.Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (childNode.Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }
Пример #2
0
        /// <summary>
        /// Builds the text collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <returns></returns>
        public static ITextCollection BuildTextCollection(IDocument document, string text)
        {
            string          xmlStartTag   = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ITextCollection txtCollection = new ITextCollection();

            text         = WhiteSpaceHelper.GetWhiteSpaceXml(text);
            text         = text.Replace("\t", "<t/>");
            text         = text.Replace("\n", "<n/>");
            xmlStartTag += "<txt>" + text + "</txt>";

            XDocument xmlDoc = XDocument.Parse(xmlStartTag);

            XElement nodeStart = xmlDoc.Root;

            if (nodeStart != null)
            {
                if (nodeStart.HasElements)
                {
                    foreach (XNode childNode in nodeStart.Nodes())
                    {
                        if (childNode.NodeType == XmlNodeType.Text)
                        {
                            txtCollection.Add(new SimpleText(document, ((XText)childNode).Value));
                        }
                        else if (((XElement)childNode).Name == "ws")
                        {
                            if (((XElement)childNode).Attributes().Count() == 1)
                            {
                                XAttribute nodeCnt = ((XElement)childNode).Attribute("id");
                                if (nodeCnt != null)
                                {
                                    txtCollection.Add(new WhiteSpace(document, Convert.ToInt32(nodeCnt.Value)));
                                }
                            }
                        }
                        else if (((XElement)childNode).Name == "t")
                        {
                            txtCollection.Add(new TabStop(document));
                        }
                        else if (((XElement)childNode).Name == "n")
                        {
                            txtCollection.Add(new LineBreak(document));
                        }
                    }
                }
                else
                {
                    txtCollection.Add(new SimpleText(document, text));
                }
            }
            return(txtCollection);
        }