示例#1
0
        public object saveXML([Optional] DOMNode node)
        {
            XmlNode xml_node;

            if (node == null)
            {
                xml_node = XmlNode;
            }
            else
            {
                xml_node = node.XmlNode;
                if (xml_node.OwnerDocument != XmlDocument && xml_node != XmlNode)
                {
                    DOMException.Throw(ExceptionCode.WrongDocument);
                    return(false);
                }
            }

            // determine output encoding
            Encoding encoding = XmlDom.GetNodeEncoding(xml_node);

            using (MemoryStream stream = new MemoryStream())
            {
                // use a XML writer and set its Formatting proprty to Formatting.Indented
                using (XmlTextWriter writer = new XmlTextWriter(stream, encoding))
                {
                    writer.Formatting = (_formatOutput ? Formatting.Indented : Formatting.None);
                    xml_node.WriteTo(writer);
                }

                return(new PhpBytes(stream.ToArray()));
            }
        }
示例#2
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);
            }
        }