Exemple #1
0
        public object transformToUri(DOMDocument doc, string uri)
        {
            using (PhpStream stream = PhpStream.Open(uri, "wt"))
            {
                if (stream == null)
                {
                    return(false);
                }

                // transform the document
                try
                {
                    TransformToStream(doc.XmlNode, xsltArgumentList, stream.RawStream);
                }
                catch (XsltException e)
                {
                    if (e.InnerException != null)
                    {
                        // ScriptDiedException etc.
                        throw e.InnerException;
                    }

                    PhpException.Throw(PhpError.Warning, e.Message);
                    return(false);
                }
                catch (InvalidOperationException e)
                {
                    PhpException.Throw(PhpError.Warning, e.Message);
                    return(false);
                }

                // TODO:
                return(stream.RawStream.CanSeek ? stream.RawStream.Position : 1);
            }
        }
Exemple #2
0
        public static object load([This] DOMDocument instance, string fileName, [Optional] int options)
        {
            // this method can be called both statically and via an instance
            bool static_call;

            if (instance == null)
            {
                static_call = true;
                instance    = new DOMDocument();
            }
            else
            {
                static_call = false;
            }

            instance._isHtmlDocument = false;

            using (PhpStream stream = PhpStream.Open(fileName, "rt"))
            {
                if (stream == null)
                {
                    return(false);
                }

                try
                {
                    if (instance._validateOnParse)
                    {
                        // create a validating XML reader
                        XmlReaderSettings settings = new XmlReaderSettings();
#pragma warning disable 618
                        settings.ValidationType = ValidationType.Auto;
#pragma warning restore 618

                        instance.XmlDocument.Load(XmlReader.Create(stream.RawStream, settings));
                    }
                    else
                    {
                        instance.XmlDocument.Load(stream.RawStream);
                    }
                }
                catch (XmlException e)
                {
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
                    return(false);
                }
                catch (IOException e)
                {
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
                    return(false);
                }
            }

            return(static_call ? instance : (object)true);
        }
Exemple #3
0
 public object importStylesheet(DOMDocument doc)
 {
     try
     {
         Load(doc.XmlDocument);
     }
     catch (XsltException e)
     {
         PhpException.Throw(PhpError.Warning, e.Message);
         return(false);
     }
     return(true);
 }
Exemple #4
0
        public static object loadXML([This] DOMDocument instance, string xmlString, [Optional] int options)
        {
            // this method can be called both statically and via an instance
            bool static_call;

            if (instance == null)
            {
                static_call = true;
                instance    = new DOMDocument();
            }
            else
            {
                static_call = false;
            }

            var result = instance.loadXMLInternal(xmlString, options, false);

            return(static_call ? instance : (object)result);
        }
Exemple #5
0
        public object transformToXml(DOMDocument doc)
        {
            // writing to a StringWriter would result in forcing UTF-16 encoding
            using (MemoryStream stream = new MemoryStream())
            {
                XmlWriterSettings settings = GetOutputSettings();
                if (settings.Encoding is UTF8Encoding)
                {
                    // no BOM in UTF-8 please!
                    settings          = settings.Clone();
                    settings.Encoding = new UTF8Encoding(false);
                }

                using (XmlWriter writer = XmlWriter.Create(stream, settings))
                {
                    // transform the document
                    try
                    {
                        TransformToWriter(doc.XmlNode, xsltArgumentList, writer);
                    }
                    catch (XsltException e)
                    {
                        if (e.InnerException != null)
                        {
                            // ScriptDiedException etc.
                            throw e.InnerException;
                        }

                        PhpException.Throw(PhpError.Warning, e.Message);
                        return(false);
                    }
                    catch (InvalidOperationException e)
                    {
                        PhpException.Throw(PhpError.Warning, e.Message);
                        return(false);
                    }
                }

                return(new PhpBytes(stream.ToArray()));
            }
        }
Exemple #6
0
		public object transformToXml(DOMDocument doc)
		{
			// writing to a StringWriter would result in forcing UTF-16 encoding
			using (MemoryStream stream = new MemoryStream())
			{
				XmlWriterSettings settings = GetOutputSettings();
				if (settings.Encoding is UTF8Encoding)
				{
					// no BOM in UTF-8 please!
					settings = settings.Clone();
					settings.Encoding = new UTF8Encoding(false);
				}

				using (XmlWriter writer = XmlWriter.Create(stream, settings))
				{
					// transform the document
					try
					{
						TransformToWriter(doc.XmlNode, xsltArgumentList, writer);
					}
					catch (XsltException e)
					{
						if (e.InnerException != null)
						{
							// ScriptDiedException etc.
							throw e.InnerException;
						}

						PhpException.Throw(PhpError.Warning, e.Message);
						return false;
					}
					catch (InvalidOperationException e)
					{
						PhpException.Throw(PhpError.Warning, e.Message);
						return false;
					}
				}

				return new PhpBytes(stream.ToArray());
			}
		}
Exemple #7
0
		public object transformToUri(DOMDocument doc, string uri)
		{
			using (PhpStream stream = PhpStream.Open(uri, "wt"))
			{
				if (stream == null) return false;

				// transform the document
				try
				{
					TransformToStream(doc.XmlNode, xsltArgumentList, stream.RawStream);
				}
				catch (XsltException e)
				{
					if (e.InnerException != null)
					{
						// ScriptDiedException etc.
						throw e.InnerException;
					}

					PhpException.Throw(PhpError.Warning, e.Message);
					return false;
				}
				catch (InvalidOperationException e)
				{
					PhpException.Throw(PhpError.Warning, e.Message);
					return false;
				}

				// TODO:
				return (stream.RawStream.CanSeek ? stream.RawStream.Position : 1);
			}
		}
Exemple #8
0
		public object importStylesheet(DOMDocument doc)
		{
			try
			{
				Load(doc.XmlDocument);
			}
			catch (XsltException e)
			{
				PhpException.Throw(PhpError.Warning, e.Message);
				return false;
			}
			return true;
		}
Exemple #9
0
		public static object loadXML([This] DOMDocument instance, string xmlString, [Optional] int options)
		{
			// this method can be called both statically and via an instance
			bool static_call;
			if (instance == null)
			{
				static_call = true;
				instance = new DOMDocument();
			}
			else static_call = false;

            var result = instance.loadXMLInternal(xmlString, options, false);
            return static_call ? instance : (object)result;
		}
Exemple #10
0
		public static object load([This] DOMDocument instance, string fileName, [Optional] int options)
		{
			// this method can be called both statically and via an instance
			bool static_call;
			if (instance == null)
			{
				static_call = true;
				instance = new DOMDocument();
			}
			else static_call = false;

            instance._isHtmlDocument = false;

			using (PhpStream stream = PhpStream.Open(fileName, "rt"))
			{
				if (stream == null) return false;

				try
				{
					if (instance._validateOnParse)
					{
						// create a validating XML reader
						XmlReaderSettings settings = new XmlReaderSettings();
#pragma warning disable 618
						settings.ValidationType = ValidationType.Auto;
#pragma warning restore 618

						instance.XmlDocument.Load(XmlReader.Create(stream.RawStream, settings));
					}
					else instance.XmlDocument.Load(stream.RawStream);
				}
				catch (XmlException e)
				{
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
					return false;
				}
				catch (IOException e)
				{
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
					return false;
				}
			}

			return (static_call ? instance : (object)true);
		}
Exemple #11
0
		public static object loadXML([This] DOMDocument instance, string xmlString, [Optional] int options)
		{
			// this method can be called both statically and via an instance
			bool static_call;
			if (instance == null)
			{
				static_call = true;
				instance = new DOMDocument();
			}
			else static_call = false;

            instance._isHtmlDocument = false;

			try
			{
				if (instance._validateOnParse)
				{
					// create a validating XML reader
					XmlReaderSettings settings = new XmlReaderSettings();
#pragma warning disable 618
					settings.ValidationType = ValidationType.Auto;
#pragma warning restore 618
                    
					instance.XmlDocument.Load(XmlReader.Create(new StringReader(xmlString), settings));
				}
				else instance.XmlDocument.LoadXml(xmlString);
			}
			catch (XmlException e)
			{
				PhpException.Throw(PhpError.Warning, e.Message);
				return false;
			}
			catch (IOException e)
			{
				PhpException.Throw(PhpError.Warning, e.Message);
				return false;
			}

			return (static_call ? instance : (object)true);
		}
Exemple #12
0
		public void __construct(DOMDocument document)
		{
			this.XPathNavigator = document.XmlDocument.CreateNavigator();
            InitNamespaceManager(document._isHtmlDocument);
		}
Exemple #13
0
 public void __construct(DOMDocument document)
 {
     this.XPathNavigator = document.XmlDocument.CreateNavigator();
     InitNamespaceManager(document._isHtmlDocument);
 }