Beispiel #1
0
        /// <summary>
        /// Copy all children from 'source' to 'dest', within the context of the specified page.
        /// </summary>
        /// <param name="page">the page which the nodes belong to</param>
        /// <param name="source">the node to copy from</param>
        /// <param name="dest">the node to copy to</param>
        /// <param name="handleXHTMLAsHTML">if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements</param>
        private static void Copy(SgmlPage page, XmlNode source, DomNode dest, bool handleXHTMLAsHTML)
        {
            XmlNodeList nodeChildren = source.ChildNodes;

            for (int i = 0; i < nodeChildren.Count; i++)
            {
                XmlNode child = nodeChildren.Item(i);
                switch (child.NodeType)
                {
                case XmlNodeType.Element:
                    DomNode childXml = CreateFrom(page, child, handleXHTMLAsHTML);
                    dest.appendChild(childXml);
                    Copy(page, child, childXml, handleXHTMLAsHTML);
                    break;

                case XmlNodeType.Text:
                    dest.appendChild(new DomText(page, child.Value));
                    break;

                case XmlNodeType.CDATA:
                    dest.appendChild(new DomCDataSection(page, child.Value));
                    break;

                case XmlNodeType.Comment:
                    dest.appendChild(new DomComment(page, child.Value));
                    break;

                case XmlNodeType.ProcessingInstruction:
                    dest.appendChild(new DomProcessingInstruction(page, child.Name, child.Value));
                    break;

                default:
                    LOG.Warn("NodeType " + child.NodeType + " (" + child.Name + ") is not yet supported.");
                }
            }
        }
Beispiel #2
0
        /// <summary>
        /// Recursively appends a {@link Node} child to {@link DomNode} parent.
        /// </summary>
        /// <param name="page">the owner page of {@link DomElement}s to be created</param>
        /// <param name="parent">the parent DomNode</param>
        /// <param name="child">the child Node</param>
        /// <param name="handleXHTMLAsHTML">if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements</param>
        public static void AppendChild(SgmlPage page, DomNode parent, XmlNode child, bool handleXHTMLAsHTML)
        {
            XmlDocumentType documentType = child.OwnerDocument.DocumentType;

            if (documentType != null && page is XmlPage)
            {
                DomDocumentType domDoctype = new DomDocumentType(
                    page, documentType.Name, documentType.PublicId, documentType.SystemId);
                ((XmlPage)page).setDocumentType(domDoctype);
            }
            DomNode childXml = CreateFrom(page, child, handleXHTMLAsHTML);

            parent.appendChild(childXml);
            Copy(page, child, childXml, handleXHTMLAsHTML);
        }
Beispiel #3
0
        /// <summary>
        /// Copy all children from 'source' to 'dest', within the context of the specified page.
        /// </summary>
        /// <param name="page">the page which the nodes belong to</param>
        /// <param name="source">the node to copy from</param>
        /// <param name="dest">the node to copy to</param>
        /// <param name="handleXHTMLAsHTML">if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements</param>
        private static void Copy(SgmlPage page, XmlNode source, DomNode dest, bool handleXHTMLAsHTML)
        {
            XmlNodeList nodeChildren = source.ChildNodes;
            for (int i = 0; i < nodeChildren.Count; i++)
            {
                XmlNode child = nodeChildren.Item(i);
                switch (child.NodeType)
                {
                    case XmlNodeType.Element:
                        DomNode childXml = CreateFrom(page, child, handleXHTMLAsHTML);
                        dest.appendChild(childXml);
                        Copy(page, child, childXml, handleXHTMLAsHTML);
                        break;

                    case XmlNodeType.Text:
                        dest.appendChild(new DomText(page, child.Value));
                        break;

                    case XmlNodeType.CDATA:
                        dest.appendChild(new DomCDataSection(page, child.Value));
                        break;

                    case XmlNodeType.Comment:
                        dest.appendChild(new DomComment(page, child.Value));
                        break;

                    case XmlNodeType.ProcessingInstruction:
                        dest.appendChild(new DomProcessingInstruction(page, child.Name, child.Value));
                        break;

                    default:
                        LOG.Warn("NodeType " + child.NodeType + " (" + child.Name + ") is not yet supported.");
                }
            }
        }
Beispiel #4
0
 /// <summary>
 /// Recursively appends a {@link Node} child to {@link DomNode} parent.
 /// </summary>
 /// <param name="page">the owner page of {@link DomElement}s to be created</param>
 /// <param name="parent">the parent DomNode</param>
 /// <param name="child">the child Node</param>
 /// <param name="handleXHTMLAsHTML">if true elements from the XHTML namespace are handled as HTML elements instead of DOM elements</param>
 public static void AppendChild(SgmlPage page, DomNode parent, XmlNode child, bool handleXHTMLAsHTML)
 {
     XmlDocumentType documentType = child.OwnerDocument.DocumentType;
     if (documentType != null && page is XmlPage)
     {
         DomDocumentType domDoctype = new DomDocumentType(
                 page, documentType.Name, documentType.PublicId, documentType.SystemId);
         ((XmlPage)page).setDocumentType(domDoctype);
     }
     DomNode childXml = CreateFrom(page, child, handleXHTMLAsHTML);
     parent.appendChild(childXml);
     Copy(page, child, childXml, handleXHTMLAsHTML);
 }