Ejemplo n.º 1
0
        // merge multiple <head> or <body> contents into one, delete the remainder, and ensure they are owned by <html>
        private void NormaliseStructure(String tag, iText.StyledXmlParser.Jsoup.Nodes.Element htmlEl)
        {
            Elements elements = this.GetElementsByTag(tag);

            iText.StyledXmlParser.Jsoup.Nodes.Element master = elements.First();
            // will always be available as created above if not existent
            if (elements.Count > 1)
            {
                // dupes, move contents to master
                IList <iText.StyledXmlParser.Jsoup.Nodes.Node> toMove = new List <iText.StyledXmlParser.Jsoup.Nodes.Node>();
                for (int i = 1; i < elements.Count; i++)
                {
                    iText.StyledXmlParser.Jsoup.Nodes.Node dupe = elements[i];
                    foreach (iText.StyledXmlParser.Jsoup.Nodes.Node node in dupe.childNodes)
                    {
                        toMove.Add(node);
                    }
                    dupe.Remove();
                }
                foreach (iText.StyledXmlParser.Jsoup.Nodes.Node dupe in toMove)
                {
                    master.AppendChild(dupe);
                }
            }
            // ensure parented by <html>
            if (!master.Parent().Equals(htmlEl))
            {
                htmlEl.AppendChild(master);
            }
        }
 public override bool Matches(iText.StyledXmlParser.Jsoup.Nodes.Element root, iText.StyledXmlParser.Jsoup.Nodes.Element
                              element)
 {
     if (root == element)
     {
         return(false);
     }
     iText.StyledXmlParser.Jsoup.Nodes.Element parent = (iText.StyledXmlParser.Jsoup.Nodes.Element)element.Parent
                                                            ();
     while (true)
     {
         if (evaluator.Matches(root, parent))
         {
             return(true);
         }
         if (parent == root)
         {
             break;
         }
         parent = (iText.StyledXmlParser.Jsoup.Nodes.Element)parent.Parent();
     }
     return(false);
 }
 public override bool Matches(iText.StyledXmlParser.Jsoup.Nodes.Element root, iText.StyledXmlParser.Jsoup.Nodes.Element
                              element)
 {
     if (root == element)
     {
         return(false);
     }
     iText.StyledXmlParser.Jsoup.Nodes.Element parent = (iText.StyledXmlParser.Jsoup.Nodes.Element)element.Parent
                                                            ();
     return(parent != null && evaluator.Matches(root, parent));
 }