public static WAElement GetWAElementFromXML(string in_XMLContent) { try { WAElement out_WAElement = new WAElement(); XmlDocument InitialDoc = new XmlDocument(); InitialDoc.LoadXml(in_XMLContent); XmlNodeList AllParags = InitialDoc.GetElementsByTagName(WordXMLTags.WordTagName_Paragraph)[0].ChildNodes; WAElementLine tocLine = new WAElementLine(); for (int prg = 0; prg < AllParags.Count; prg++) { XmlDocument DrftXMLDoc = new XmlDocument(); DrftXMLDoc.LoadXml(AllParags[prg].OuterXml); XmlNodeList AllPTRuns = DrftXMLDoc.GetElementsByTagName(WordXMLTags.WTN_Hyperlink)[0].ChildNodes; WAElementLineField lineField = new WAElementLineField(); foreach (XmlNode WTextRun in AllPTRuns) { XmlDocument TRun = new XmlDocument(); TRun.LoadXml(WTextRun.OuterXml); XmlNode runtext = TRun.GetElementsByTagName(WordXMLTags.WordTagName_Text)[0]; XmlNode runprps = TRun.GetElementsByTagName(WordXMLTags.WordTagName_TextRun_Properties)[0]; WTextPart tpart = new WTextPart(); if (runtext != null) { tpart.Text = runtext.InnerText; if (runprps != null) { foreach (XmlNode rprp in runprps.ChildNodes) { if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Bold) { tpart.Bold = true; } if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Underline) { tpart.Underline = true; } if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Italic) { tpart.Italic = true; } } } lineField.Elements.Add(tpart); } else { lineField = new WAElementLineField(); } } tocLine.Fields.Add(lineField); } out_WAElement.Lines.Add(tocLine); return(out_WAElement); } catch (Exception Exp) { return(null); } }
public static WParagraph GetParagraphFromParagraphXMLNode(XmlNode PragraphNode) { if (PragraphNode != null) { WParagraph WPrg = new WParagraph(); WPrg.ParagraphStyle = ParagraphStyle.SimpleContainer; XmlDocument PrgXML = new XmlDocument(); PrgXML.LoadXml(PragraphNode.OuterXml); XmlNodeList wtextruns = PrgXML.GetElementsByTagName(WordXMLTags.WordTagName_TextRun); XmlNode pprps = PrgXML.GetElementsByTagName(WordXMLTags.WordTagName_Paragraph_Properties)[0]; bool isHeader = false; if (pprps != null) { foreach (XmlNode pprp in pprps.ChildNodes) { if (pprp.Name == WordXMLTags.WordTagName_Paragraph_Properties_Alignment) { if (pprp.Attributes[WordXMLTags.WordTagAttrib_Value] != null) { string aling = pprp.Attributes[WordXMLTags.WordTagAttrib_Value].Value; if (aling.ToLower() == Alignment.Left.ToString().ToLower()) { WPrg.Alingment = Alignment.Left; } else if (aling.ToLower() == Alignment.Right.ToString().ToLower()) { WPrg.Alingment = Alignment.Right; } else if (aling.ToLower() == Alignment.Center.ToString().ToLower()) { WPrg.Alingment = Alignment.Center; } else if (aling.ToLower() == Alignment.Both.ToString().ToLower()) { WPrg.Alingment = Alignment.Both; } else { WPrg.Alingment = Alignment.Left; } } } else if (pprp.Name == WordXMLTags.WTN_Pgraph_Properties_Style) { if (pprp.Attributes[WordXMLTags.WordTagAttrib_Value] != null) { string pstyle = pprp.Attributes[WordXMLTags.WordTagAttrib_Value].Value; WPrg.ParagraphStyle = ParagraphStyle.SimpleContainer; if (pstyle.ToLower() == "heading1") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading1; } else if (pstyle.ToLower() == "heading2") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading2; } else if (pstyle.ToLower() == "heading3") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading3; } else if (pstyle.ToLower() == "heading4") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading4; } else if (pstyle.ToLower() == "heading5") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading5; } else if (pstyle.ToLower() == "heading6") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading6; } else if (pstyle.ToLower() == "heading7") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading7; } else if (pstyle.ToLower() == "heading8") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading8; } else if (pstyle.ToLower() == "heading9") { WPrg.ParagraphStyle = ParagraphStyle.WordHeading9; } else if (pstyle.ToLower().Contains("heading")) { WPrg.ParagraphStyle = ParagraphStyle.WordHeading9; } if (pstyle.ToLower().Contains("heading")) { isHeader = true; } } } else if (pprp.Name == WordXMLTags.WTN_Pgraph_LPrp && isHeader == false) { string ilvl = null; string ilfo = null; foreach (XmlNode lprp in pprp.ChildNodes) { if (lprp.Name == WordXMLTags.WTN_Pgraph_LPrp_LLvl1) { if (lprp.Attributes[WordXMLTags.WordTagAttrib_Value] != null) { ilvl = lprp.Attributes[WordXMLTags.WordTagAttrib_Value].Value; } } else if (lprp.Name == WordXMLTags.WTN_Pgraph_LPrp_LLvl2) { if (lprp.Attributes[WordXMLTags.WordTagAttrib_Value] != null) { ilfo = lprp.Attributes[WordXMLTags.WordTagAttrib_Value].Value; } } } if (ilfo != null) { WPrg.ListID = Convert.ToInt32(ilfo); } if (ilvl != null) { WPrg.ListItemLevel = Convert.ToInt32(ilvl); } WPrg.ParagraphStyle = ParagraphStyle.ListItemElement; } } } foreach (XmlNode WTextRun in wtextruns) { XmlDocument TRun = new XmlDocument(); TRun.LoadXml(WTextRun.OuterXml); XmlNode runtext = TRun.GetElementsByTagName(WordXMLTags.WordTagName_Text)[0]; XmlNode runprps = TRun.GetElementsByTagName(WordXMLTags.WordTagName_TextRun_Properties)[0]; WTextPart tpart = new WTextPart(); if (TRun.GetElementsByTagName(WordXMLTags.WTN_Picture)[0] != null) { string[] AVlArr = GetAtribValue(TRun.GetElementsByTagName(WordXMLTags.WTN_Picture)[0], WordXMLTags.WTA_Style).Split(';'); int rlWidth = -1, rlHeight = -1; if (AVlArr != null) { if (AVlArr.Length > 0) { string rsWidth = Array.Find(AVlArr, ln => ln.ToLower().StartsWith("width")).ToString(); string rsHeight = Array.Find(AVlArr, ln => ln.ToLower().StartsWith("height")).ToString(); if (string.IsNullOrEmpty(rsWidth) != true) { rsWidth = rsWidth.Substring("width".Length); string tmpsWidth = string.Empty; foreach (char se in rsWidth) { if (Array.IndexOf(Numebers, se) >= 0) { tmpsWidth += se; } else if (se == '.' || se == ',') { break; } } try { rlWidth = int.Parse(tmpsWidth); } catch { rlWidth = -1; } } if (string.IsNullOrEmpty(rsHeight) != true) { rsWidth = rsWidth.Substring("height".Length); string tmpsHeight = string.Empty; foreach (char se in rsHeight) { if (Array.IndexOf(Numebers, se) >= 0) { tmpsHeight += se; } else if (se == '.' || se == ',') { break; } } try { rlHeight = int.Parse(tmpsHeight); } catch { rlHeight = -1; } } } } WPrg.Elements.Add(new WImage() { Width = rlWidth, Height = rlHeight }); } tpart.Text = (runtext != null) ? runtext.InnerText : null; if (runprps != null) { foreach (XmlNode rprp in runprps.ChildNodes) { if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Bold) { tpart.Bold = true; } if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Underline) { tpart.Underline = true; } if (rprp.Name == WordXMLTags.WordTagName_TextRun_Properties_Italic) { tpart.Italic = true; } } } WPrg.Elements.Add(tpart); } //if (WTCell.WordTableCellValue != null && WTCell.WordTableCellValue != string.Empty) //{ // WTCell.WordTableCellValue += WTable.SeparatorFor_Paragraph; //} PrgXML.RemoveAll(); return(WPrg); } return(null); }