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())); } }
public object setAttributeNS(string namespaceUri, string qualifiedName, string value) { if (!IsAssociated) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } // parse the qualified name string local_name, prefix; XmlDom.ParseQualifiedName(qualifiedName, out prefix, out local_name); XmlAttribute attr = XmlElement.Attributes[local_name, namespaceUri]; if (attr == null) { attr = XmlNode.OwnerDocument.CreateAttribute(qualifiedName, namespaceUri); XmlElement.Attributes.Append(attr); } else { attr.Prefix = prefix; } attr.Value = value; return(true); }
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); } }