Beispiel #1
0
        /// <summary>
        /// Creates the paragraph collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <param name="useStandardStyle">if set to <c>true</c> [use standard style].</param>
        /// <param name="paragraphSeperator">The paragraph seperator.</param>
        /// <returns></returns>
        public static ParagraphCollection CreateParagraphCollection(IDocument document, string text, bool useStandardStyle, string paragraphSeperator)
        {
            string xmlStartTag				= "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ParagraphCollection pCollection	= new ParagraphCollection();
            text							= text.Replace(paragraphSeperator, "<p/>");
            xmlStartTag						+= "<pg>"+text+"</pg>";

            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)
                        {
                            Paragraph paragraph		= null;

                            if(useStandardStyle)
                                paragraph			= ParagraphBuilder.CreateStandardTextParagraph(document);
                            else
                                paragraph			= ParagraphBuilder.CreateParagraphWithCustomStyle(
                                    document, "P"+Convert.ToString(document.DocumentMetadata.ParagraphCount+nodeStart.ChildNodes.Count+1));

                            paragraph.TextContent	= TextBuilder.BuildTextCollection(document, childNode.InnerText);
                            pCollection.Add(paragraph);
                        }
                        else
                        {
                            Paragraph paragraph		= null;

                            if(useStandardStyle)
                                paragraph			= ParagraphBuilder.CreateStandardTextParagraph(document);
                            else
                                paragraph			= ParagraphBuilder.CreateParagraphWithCustomStyle(
                                    document, "P"+Convert.ToString(document.DocumentMetadata.ParagraphCount+nodeStart.ChildNodes.Count+1));

                            pCollection.Add(paragraph);
                        }
                    }
                }
                else
                {
                    Paragraph paragraph		= null;

                    if(useStandardStyle)
                        paragraph			= ParagraphBuilder.CreateStandardTextParagraph(document);
                    else
                        paragraph			= ParagraphBuilder.CreateParagraphWithCustomStyle(
                            document, "P"+Convert.ToString(document.DocumentMetadata.ParagraphCount+1));

                    paragraph.TextContent	 = TextBuilder.BuildTextCollection(document, nodeStart.InnerText);
                    pCollection.Add(paragraph);
                }
            return pCollection;
        }
Beispiel #2
0
        /// <summary>
        /// Creates the paragraph collection.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="text">The text.</param>
        /// <param name="useStandardStyle">if set to <c>true</c> [use standard style].</param>
        /// <param name="paragraphSeperator">The paragraph seperator.</param>
        /// <returns></returns>
        public static ParagraphCollection CreateParagraphCollection(IDocument document, string text,
                                                                    bool useStandardStyle, string paragraphSeperator)
        {
            string xmlStartTag = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>";
            ParagraphCollection pCollection = new ParagraphCollection();

            text         = text.Replace(paragraphSeperator, "<p/>");
            xmlStartTag += "<pg>" + text + "</pg>";

            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)
                        {
                            Paragraph paragraph;

                            if (useStandardStyle)
                            {
                                paragraph = CreateStandardTextParagraph(document);
                            }
                            else
                            {
                                paragraph = CreateParagraphWithCustomStyle(
                                    document,
                                    "P" +
                                    Convert.ToString(document.DocumentMetadata.ParagraphCount +
                                                     nodeStart.Nodes().Count() + 1));
                            }

                            paragraph.TextContent = TextBuilder.BuildTextCollection(document, ((XText)childNode).Value);
                            pCollection.Add(paragraph);
                        }
                        else
                        {
                            Paragraph paragraph;

                            if (useStandardStyle)
                            {
                                paragraph = CreateStandardTextParagraph(document);
                            }
                            else
                            {
                                paragraph = CreateParagraphWithCustomStyle(
                                    document,
                                    "P" +
                                    Convert.ToString(document.DocumentMetadata.ParagraphCount +
                                                     nodeStart.Nodes().Count() + 1));
                            }

                            pCollection.Add(paragraph);
                        }
                    }
                }
                else
                {
                    Paragraph paragraph;

                    if (useStandardStyle)
                    {
                        paragraph = CreateStandardTextParagraph(document);
                    }
                    else
                    {
                        paragraph = CreateParagraphWithCustomStyle(
                            document, "P" + Convert.ToString(document.DocumentMetadata.ParagraphCount + 1));
                    }

                    paragraph.TextContent = TextBuilder.BuildTextCollection(document, nodeStart.Value);
                    pCollection.Add(paragraph);
                }
            }
            return(pCollection);
        }