/// <summary> /// Creates an empty DocumentType node. Entity declarations and /// notations are not made available. Entity reference expansions and /// default attribute additions do not occur. /// </summary> /// <param name="qualifiedName"> /// The qualified name of the document type to be created. /// </param> /// <param name="publicId"> /// The external subset public identifier. /// </param> /// <param name="systemId"> /// The external subset system identifier. /// </param> /// <returns> /// A new DocumentType node with the owner document set to null. /// </returns> public IDocumentType CreateDocumentType(String qualifiedName, String publicId, String systemId) { if (qualifiedName == null) throw new ArgumentNullException("qualifiedName"); if (!qualifiedName.IsXmlName()) throw new DomException(DomError.InvalidCharacter); else if (!qualifiedName.IsQualifiedName()) throw new DomException(DomError.Namespace); return new DocumentType(_owner, qualifiedName) { PublicIdentifier = publicId, SystemIdentifier = systemId }; }
/// <summary> /// Adds a new attribute or changes the value of an existing attribute /// on the specified element. /// </summary> /// <param name="namespaceUri"> /// A string specifying the namespace of the attribute. /// </param> /// <param name="name">The name of the attribute as a string.</param> /// <param name="value">The desired new value of the attribute.</param> public void SetAttribute(String namespaceUri, String name, String value) { if (value != null) { if (String.IsNullOrEmpty(namespaceUri)) namespaceUri = null; if (!name.IsXmlName()) throw new DomException(DomError.InvalidCharacter); else if (!name.IsQualifiedName()) throw new DomException(DomError.Namespace); var index = name.IndexOf(Symbols.Colon); var prefix = index >= 0 ? name.Substring(0, index) : null; var localName = index >= 0 ? name.Substring(index + 1) : name; if (prefix != null && namespaceUri == null) throw new DomException(DomError.Namespace); if (prefix == Namespaces.XmlPrefix && namespaceUri != Namespaces.XmlUri) throw new DomException(DomError.Namespace); else if ((name == Namespaces.XmlNsPrefix || prefix == Namespaces.XmlNsPrefix) && namespaceUri != Namespaces.XmlNsUri) throw new DomException(DomError.Namespace); else if (namespaceUri == Namespaces.XmlNsUri && name != Namespaces.XmlNsPrefix && prefix != Namespaces.XmlNsPrefix) throw new DomException(DomError.Namespace); for (int i = 0; i < _attributes.Count; i++) { if (_attributes[i].LocalName == localName && _attributes[i].NamespaceUri == namespaceUri) { _attributes[i].Value = value; return; } } _attributes.Add(new Attr(this, prefix, localName, value, namespaceUri)); AttributeChanged(localName, namespaceUri, null); } else RemoveAttribute(namespaceUri, name); }
/// <summary> /// Adds a new attribute or changes the value of an existing attribute /// on the specified element. /// </summary> /// <param name="name">The name of the attribute as a string.</param> /// <param name="value">The desired new value of the attribute.</param> public void SetAttribute(String name, String value) { if (value != null) { if (!name.IsXmlName()) throw new DomException(DomError.InvalidCharacter); if (_namespace == Namespaces.HtmlUri) name = name.ToLowerInvariant(); for (int i = 0; i < _attributes.Count; i++) { if (_attributes[i].Prefix == null && _attributes[i].LocalName == name) { _attributes[i].Value = value; return; } } _attributes.Add(new Attr(this, name, value)); AttributeChanged(name, null, null); } else RemoveAttribute(name); }
/// <summary> /// Creates a ProcessingInstruction node given the specified name and /// data strings. /// </summary> /// <param name="target"> /// The target part of the processing instruction. /// </param> /// <param name="data">The data for the node.</param> /// <returns>A new processing instruction.</returns> public IProcessingInstruction CreateProcessingInstruction(String target, String data) { if (!target.IsXmlName() || data.Contains("?>")) throw new DomException(DomError.InvalidCharacter); return new ProcessingInstruction(this, target) { Data = data }; }
/// <summary> /// Creates a new element with the given tag name and namespace URI. /// </summary> /// <param name="namespaceUri"> /// Specifies the namespace URI to associate with the element. /// </param> /// <param name="qualifiedName"> /// A string that specifies the type of element to be created. /// </param> /// <returns>The created element.</returns> public IElement CreateElement(String namespaceUri, String qualifiedName) { if (String.IsNullOrEmpty(namespaceUri)) namespaceUri = null; if (!qualifiedName.IsXmlName()) throw new DomException(DomError.InvalidCharacter); else if (!qualifiedName.IsQualifiedName()) throw new DomException(DomError.Namespace); var parts = qualifiedName.Split(':'); var prefix = parts.Length == 2 ? parts[0] : null; var localName = parts.Length == 2 ? parts[1] : qualifiedName; if ((prefix == Namespaces.XmlPrefix && namespaceUri != Namespaces.XmlUri) || ((qualifiedName == Namespaces.XmlNsPrefix || prefix == Namespaces.XmlNsPrefix) && namespaceUri != Namespaces.XmlNsUri) || (namespaceUri == Namespaces.XmlNsUri && (qualifiedName != Namespaces.XmlNsPrefix || prefix != Namespaces.XmlNsPrefix))) throw new DomException(DomError.Namespace); var element = default(Element); if (namespaceUri == Namespaces.HtmlUri) element = Factory.HtmlElements.Create(this, localName, prefix); else if (namespaceUri == Namespaces.SvgUri) element = Factory.SvgElements.Create(this, localName, prefix); else if (namespaceUri == Namespaces.MathMlUri) element = Factory.MathElements.Create(this, localName, prefix); else element = new Element(this, localName, prefix, namespaceUri); return element; }
/// <summary> /// Creates a new element with the given tag name. /// </summary> /// <param name="localName"> /// A string that specifies the type of element to be created. /// </param> /// <returns>The created element object.</returns> public IElement CreateElement(String localName) { if (!localName.IsXmlName()) throw new DomException(DomError.InvalidCharacter); return Factory.HtmlElements.Create(this, localName); }
/// <summary> /// Adds a new attribute or changes the value of an existing attribute /// on the specified element. /// </summary> /// <param name="name">The name of the attribute as a string.</param> /// <param name="value">The desired new value of the attribute.</param> public void SetAttribute(String name, String value) { if (value != null) { if (!name.IsXmlName()) throw new DomException(DomError.InvalidCharacter); if (String.Equals(_namespace, Namespaces.HtmlUri, StringComparison.Ordinal)) name = name.ToLowerInvariant(); this.SetOwnAttribute(name, value); } else RemoveAttribute(name); }
/// <summary> /// Creates an Attr of the given name. /// </summary> /// <param name="localName">The name of the attribute.</param> /// <returns>A new Attr object.</returns> public IAttr CreateAttribute(String localName) { if (!localName.IsXmlName()) throw new DomException(DomError.InvalidCharacter); return new Attr(localName); }
public void SetAttribute(String name, String value) { if (value != null) { if (!name.IsXmlName()) throw new DomException(DomError.InvalidCharacter); if (_namespace.Is(NamespaceNames.HtmlUri)) name = name.ToLowerInvariant(); this.SetOwnAttribute(name, value); } else { RemoveAttribute(name); } }