Exemplo n.º 1
0
        public object save(string fileName, [Optional] int options)
        {
            using (PhpStream stream = PhpStream.Open(fileName, "wt"))
            {
                if (stream == null)
                {
                    return(false);
                }

                try
                {
                    // direct stream write indents
                    if (_formatOutput)
                    {
                        XmlDocument.Save(stream.RawStream);
                    }
                    else
                    {
                        Encoding encoding = XmlDom.GetNodeEncoding(XmlNode);

                        using (XmlTextWriter writer = new XmlTextWriter(stream.RawStream, encoding))
                        {
                            XmlDocument.Save(writer);
                        }
                    }
                }
                catch (XmlException e)
                {
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
                    return(null);
                }
                catch (IOException e)
                {
                    PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, fileName));
                    return(false);
                }

                // TODO:
                return(stream.RawStream.CanSeek ? stream.RawStream.Position : 1);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads provided XML string into this <see cref="DOMDocument"/>.
        /// </summary>
        /// <param name="xmlString">String representing XML document.</param>
        /// <param name="options">PHP options.</param>
        /// <param name="isHtml">Whether the <paramref name="xmlString"/> represents XML generated from HTML document (then it may contain some invalid XML characters).</param>
        /// <returns></returns>
        private bool loadXMLInternal(string xmlString, int options, bool isHtml)
        {
            this._isHtmlDocument = isHtml;

            var stream = new StringReader(xmlString);

            try
            {
                XmlReaderSettings settings = new XmlReaderSettings();

                // validating XML reader
                if (this._validateOnParse)
#pragma warning disable 618
                {
                    settings.ValidationType = ValidationType.Auto;
                }
#pragma warning restore 618

                // do not check invalid characters in HTML (XML)
                if (isHtml)
                {
                    settings.CheckCharacters = false;
                }

                // load the document
                this.XmlDocument.Load(XmlReader.Create(stream, settings));

                // done
                return(true);
            }
            catch (XmlException e)
            {
                PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, null));
                return(false);
            }
            catch (IOException e)
            {
                PhpLibXml.IssueXmlError(new PhpLibXml.XmlError(PhpLibXml.LIBXML_ERR_ERROR, 0, 0, 0, e.Message, null));
                return(false);
            }
        }