Example #1
0
 internal void Insert(Token.Character characterToken)
 {
     Node node;
     // characters in script and style go in as datanodes, not text nodes
     string tagName = CurrentElement().TagName;
     if (tagName.Equals("script") || tagName.Equals("style"))
     {
         node = new DataNode(characterToken.GetData(), baseUri);
     }
     else
     {
         node = new TextNode(characterToken.GetData(), baseUri);
     }
     CurrentElement().AppendChild(node);
 }
Example #2
0
 public void Head(Node source, int depth)
 {
     if (source is Element)
     {
         Element sourceEl = (Element)source;
         if (this._enclosing.whitelist.IsSafeTag(sourceEl.TagName))
         {
             // safe, clone and copy safe attrs
             Cleaner.ElementMeta meta = this._enclosing.CreateSafeElement(sourceEl);
             Element destChild = meta.el;
             this.destination.AppendChild(destChild);
             this.numDiscarded += meta.numAttribsDiscarded;
             this.destination = destChild;
         }
         else
         {
             if (source != this.root)
             {
                 // not a safe tag, so don't add. don't count root against discarded.
                 this.numDiscarded++;
             }
         }
     }
     else
     {
         if (source is TextNode)
         {
             TextNode sourceText = (TextNode)source;
             TextNode destText = new TextNode(sourceText.WholeText, source.BaseUri);
             this.destination.AppendChild(destText);
         }
         else
         {
             if (source is DataNode && this._enclosing.whitelist.IsSafeTag(source.Parent.NodeName))
             {
                 DataNode sourceData = (DataNode)source;
                 DataNode destData = new DataNode(sourceData.WholeData, source.BaseUri);
                 this.destination.AppendChild(destData);
             }
             else
             {
                 // else, we don't care about comments, xml proc instructions, etc
                 this.numDiscarded++;
             }
         }
     }
 }