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 evaluate(string expr, [Optional] DOMNode context) { XPathNavigator navigator = GetNavigator(context); if (navigator == null) { return(false); } object result; try { result = navigator.Evaluate(expr, XmlNamespaceManager); } catch (Exception ex) { DOMException.Throw(ExceptionCode.SyntaxError, ex.Message); return(false); } // the result can be bool, double, string, or iterator XPathNodeIterator iterator = result as XPathNodeIterator; if (iterator != null) { return(IteratorToList(iterator)); } else { return(result); } }
public object setAttributeNodeNS(DOMAttr attribute) { if (!IsAssociated) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } attribute.Associate(XmlElement.OwnerDocument); if (XmlNode.OwnerDocument != attribute.XmlNode.OwnerDocument) { DOMException.Throw(ExceptionCode.WrongDocument); return(null); } XmlAttribute attr = XmlElement.Attributes[attribute.localName, attribute.namespaceURI]; if (attr != null) { XmlElement.Attributes.Remove(attr); XmlElement.Attributes.Append(attribute.XmlAttribute); return(new DOMAttr(attr)); } else { XmlElement.Attributes.Append(attribute.XmlAttribute); return(null); } }
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 substringData(int offset, int count) { if (offset < 0 || count < 0 || offset > XmlCharacterData.Length) { DOMException.Throw(ExceptionCode.IndexOutOfBounds); return(false); } return(XmlCharacterData.Substring(offset, count)); }
public bool insertData(int offset, string arg) { if (offset < 0 || offset > XmlCharacterData.Length) { DOMException.Throw(ExceptionCode.IndexOutOfBounds); return(false); } XmlCharacterData.InsertData(offset, arg); return(true); }
public bool deleteData(int offset, int count) { if (offset < 0 || count < 0 || offset > XmlCharacterData.Length) { DOMException.Throw(ExceptionCode.IndexOutOfBounds); return(false); } XmlCharacterData.DeleteData(offset, count); return(true); }
public bool replaceData(int offset, int count, string arg) { if (offset < 0 || count < 0 || offset > length) { DOMException.Throw(ExceptionCode.IndexOutOfBounds); return(false); } XmlCharacterData.ReplaceData(offset, count, arg); return(true); }
/// <summary> /// Performs a child-adding action with error checks. /// </summary> private XmlNode CheckedChildOperation(DOMNode /*!*/ newNode, DOMNode auxNode, NodeAction /*!*/ action) { newNode.Associate(XmlNode.OwnerDocument != null ? XmlNode.OwnerDocument : (XmlDocument)XmlNode); // check for readonly node if (XmlNode.IsReadOnly || (newNode.XmlNode.ParentNode != null && newNode.XmlNode.ParentNode.IsReadOnly)) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(null); } // check for owner document mismatch if (XmlNode.OwnerDocument != null ? XmlNode.OwnerDocument != newNode.XmlNode.OwnerDocument : XmlNode != newNode.XmlNode.OwnerDocument) { DOMException.Throw(ExceptionCode.WrongDocument); return(null); } XmlNode result; try { result = action(newNode, auxNode); } catch (InvalidOperationException) { // the current node is of a type that does not allow child nodes of the type of the newNode node // or the newNode is an ancestor of this node. DOMException.Throw(ExceptionCode.BadHierarchy); return(null); } catch (ArgumentException) { // check for newNode == this which System.Xml reports as ArgumentException if (newNode.XmlNode == XmlNode) { DOMException.Throw(ExceptionCode.BadHierarchy); } else { // the refNode is not a child of this node DOMException.Throw(ExceptionCode.NotFound); } return(null); } return(result); }
public object removeAttributeNS(string namespaceUri, string localName) { if (!IsAssociated) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } XmlAttribute attr = XmlElement.Attributes[localName, namespaceUri]; if (attr != null) { XmlElement.Attributes.Remove(attr); } return(true); }
private XPathNavigator GetNavigator(DOMNode context) { if (context == null) { return(XPathNavigator); } else { XmlNode node = context.XmlNode; if (node.OwnerDocument != (XmlDocument)XPathNavigator.UnderlyingObject) { DOMException.Throw(ExceptionCode.WrongDocument); return(null); } return(node.CreateNavigator()); } }
public object setAttribute(string name, string value) { if (!IsAssociated) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } XmlAttribute attr = XmlElement.Attributes[name]; if (attr == null) { attr = XmlNode.OwnerDocument.CreateAttribute(name); XmlElement.Attributes.Append(attr); } attr.Value = value; return(true); }
public object removeAttributeNode(DOMAttr attribute) { if (!IsAssociated) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } XmlAttribute attr = XmlElement.Attributes[attribute.nodeName]; if (attr == null) { DOMException.Throw(ExceptionCode.NotFound); return(false); } XmlElement.Attributes.Remove(attr); return(attribute); }
public object removeChild(DOMNode oldNode) { // check for readonly node if (XmlNode.IsReadOnly) { DOMException.Throw(ExceptionCode.DomModificationNotAllowed); return(false); } try { XmlNode.RemoveChild(oldNode.XmlNode); } catch (ArgumentException) { DOMException.Throw(ExceptionCode.NotFound); return(false); } return(oldNode); }
public object query(string expr, [Optional] DOMNode context) { XPathNavigator navigator = GetNavigator(context); if (navigator == null) { return(false); } XPathNodeIterator iterator; try { iterator = navigator.Select(expr, XmlNamespaceManager); } catch (Exception ex) { DOMException.Throw(ExceptionCode.SyntaxError, ex.Message); return(false); } // create the resulting node list return(IteratorToList(iterator)); }
public static object createDocument([This] DOMImplementation instance, string namespaceUri, string qualifiedName, [Nullable] DOMDocumentType docType) { XmlImplementation impl = (instance != null ? instance.XmlImplementation : new XmlImplementation()); XmlDocument doc = impl.CreateDocument(); if (docType != null) { if (!docType.IsAssociated) { docType.Associate(doc); } else { DOMException.Throw(ExceptionCode.WrongDocument); return(false); } } doc.AppendChild(docType.XmlNode); doc.AppendChild(doc.CreateElement(qualifiedName, namespaceUri)); return(new DOMDocument(doc)); }
protected override DObject CloneObjectInternal(DTypeDesc caller, ScriptContext context, bool deepCopyFields) { DOMException.Throw(ExceptionCode.InvalidState); return(null); }