示例#1
0
        public DOMDocument transformToDoc(DOMNode node)
        {
            var doc = PhpXmlDocument.Create();

            using (MemoryStream stream = new MemoryStream())
            {
                if (!TransformInternal(node.XmlNode, stream))
                {
                    return(null);
                }

                stream.Seek(0, SeekOrigin.Begin);

                // build the resulting XML document
                try
                {
                    doc.Load(stream);
                }
                catch (XmlException e)
                {
                    PhpException.Throw(PhpError.Warning, e.Message);
                    return(null);
                }
            }

            return(new DOMDocument(doc));
        }
示例#2
0
        /// <summary>
        /// Finds all tags Xinclude and treats everyone recursively.
        /// </summary>
        /// <param name="absoluteUri">Uri of treated xml document.</param>
        /// <param name="includeNode">Node, which references to document, which Uri is absoluteUri</param>
        /// <param name="MasterDocument">Document, where Xinclude start</param>
        /// <param name="xpointer">xpointer value, or null</param>
        void IncludeXml(string absoluteUri, XmlElement includeNode, XmlDocument MasterDocument, string xpointer)
        {
            XmlDocument document;
            bool        checkingError = false;

            if (MasterDocument == null)
            {
                document = PhpXmlDocument.Create();

                document.Load(xpointer == null
                    ? (XmlReader) new XmlBaseAwareXmlReader(absoluteUri)
                    : new XPointerReader(absoluteUri, xpointer));
            }
            else
            {
                document = MasterDocument;
            }

            // Recursion on nsPrefix resolver, declaration must be in root
            var nsPrefix = document.DocumentElement.GetPrefixOfNamespace(nsOfXIncludeNew);

            if (string.IsNullOrEmpty(nsPrefix))
            {
                nsPrefix = document.DocumentElement.GetPrefixOfNamespace(nsOfXIncludeOld);
            }

            if (!string.IsNullOrEmpty(nsPrefix))
            {
                var nsm = new XmlNamespaceManager(document.NameTable);
                nsm.AddNamespace(nsPrefix, nsOfXIncludeNew);

                // Finds all include elements, which does not have ancestor element fallback.
                XmlElement[] includeNodes = document.SelectNodes($"//{nsPrefix}:{etInclude}[ not( ancestor::{nsPrefix}:{etFallback} ) ]", nsm).OfType <XmlElement>().ToArray <XmlElement>();
                checkingError = TreatIncludes(includeNodes, document, absoluteUri, nsPrefix, nsm);
            }
            if (MasterDocument == null && !checkingError)
            {
                // There are not any includes, insert root of this document to parent document
                var parent = _documents.Pop();
                // base uri fix.
                //FixBaseUri(parent, document, includeNode);
                // lang fix
                Fixlang(parent, document);

                var importedNode = parent.ImportNode(document.DocumentElement, true); //Import method changes baseuri instead of does not change
                includeNode.ParentNode.ReplaceChild(importedNode, includeNode);
                _replaceCount++;
            }
            else
            {
                _replaceCount = -1;
            }
        }
示例#3
0
        public DOMDocument(string version = null, string encoding = null)
        {
            this.XmlDocument = PhpXmlDocument.Create();

            __construct(version, encoding);
        }