Beispiel #1
0
        public PhpString transformToXml(DOMDocument doc)
        {
            // writing to a StringWriter would result in forcing UTF-16 encoding
            using (MemoryStream stream = new MemoryStream())
            {
                if (!TransformInternal(doc.XmlNode, stream))
                {
                    return(null);
                }

                return(new PhpString(stream.ToArray()));
            }
        }
Beispiel #2
0
        //public override bool ToBoolean()
        //{
        //    return true;
        //}

        #endregion

        #region Transformation

        /// <summary>
        /// Import a stylesheet.
        /// </summary>
        /// <param name="doc">The imported style sheet passed as a <see cref="DOMDocument"/> object.</param>
        /// <returns><B>True</B> or <B>false</B>.</returns>
        public bool importStylesheet(DOMDocument doc)
        {
            try
            {
                Load(doc.XmlDocument);
            }
            catch (XsltException e)
            {
                PhpException.Throw(PhpError.Warning, e.Message);
                return(false);
            }
            return(true);
        }
Beispiel #3
0
        public static DOMDocument loadHTML(Context ctx, string source)
        {
            var document = new DOMDocument();

            if (document.loadHTML(ctx, source))
            {
                return(document);
            }
            else
            {
                return(null); // FALSE
            }
        }
Beispiel #4
0
        public static DOMDocument load(Context ctx, string fileName)
        {
            var document = new DOMDocument();

            if (document.load(ctx, fileName))
            {
                return(document);
            }
            else
            {
                return(null); // FALSE
            }
        }
Beispiel #5
0
        /// <summary>
        /// Transforms the source node to an URI applying the stylesheet given by the
        /// <see cref="importStylesheet(DOMDocument)"/> method.
        /// </summary>
        /// <param name="ctx">The current runtime context.</param>
        /// <param name="doc">The document to transform.</param>
        /// <param name="uri">The destination URI.</param>
        /// <returns>Returns the number of bytes written or <B>false</B> if an error occurred.</returns>
        public PhpValue transformToUri(Context ctx, DOMDocument doc, string uri)
        {
            using (PhpStream stream = PhpStream.Open(ctx, uri, "wt"))
            {
                if (stream == null)
                {
                    return(PhpValue.Create(false));
                }

                if (!TransformInternal(doc.XmlNode, stream.RawStream))
                {
                    return(PhpValue.Create(false));
                }

                // TODO:
                return(PhpValue.Create(stream.RawStream.CanSeek ? stream.RawStream.Position : 1));
            }
        }
Beispiel #6
0
        public void __construct(DOMDocument document)
        {
            var xmldoc = document.XmlDocument;

            if (xmldoc == null)
            {
                // invalid document provided
                throw new ArgumentException(nameof(document));
            }

            var element = xmldoc.DocumentElement;

            this.XPathNavigator = (element != null)
                ? element.CreateNavigator() // regular XPathNavigator from the root
                : xmldoc.CreateNavigator(); // empty xml document!

            InitNamespaceManagers(document._isHtmlDocument);
        }
Beispiel #7
0
 public void __construct(DOMDocument document)
 {
     this.XPathNavigator = document.XmlDocument.CreateNavigator();
     InitNamespaceManagers(document._isHtmlDocument);
 }
Beispiel #8
0
 public DOMXPath(DOMDocument document)
 {
     __construct(document);
 }