mirror of
https://github.com/BepInEx/mono.git
synced 2026-11-18 03:51:19 -10:00
* XmlInputStream.cs : Fixed Initialize() that might result in incorrect buffer. CanRead and Position should consider buffer (especially when the stream was EOF). CanSeek should use stream's CanSeek. * XmlChar.cs : added GetPredefinedEntity(). * DTDObjectModel.cs : - Modified ComputeDefaultValue() to use it. - Fixed NormalizedDefaultValue not to expect parsed value as string. - ResolveExternalEntity now detects invalid standalone specification. - DTDParameterEntityDeclaration.Value is now changed to property and keep its resolved value of literal value of external value using new Resolve (XmlResolver) method (called only by XmlTextReader). * DTDValidatingReader.cs : - It now handles entity-expanded Whitespace and SignificantWhitespace correctly. Does not raise unexpected text not allowed error. - Fixed MoveToAttribute()s to move internal reader correctly, and should be able to move in other cases than on element node. - On Read()ing document type and ResolveEntity(), it now sets XmlResolver on text reader. - On ID constraints check and type verification, it now uses normalized attribute or its tokenized value(s). - Fixed ValidateAttributes() to add default values when ValidationType is Auto. * XmlParserContext.cs : added internal Dtd setter. * XmlParserInput.cs : InsertParameterEntityBuffer() should add surrounding whitespaces. Removed unused code block. * XmlTextReader.cs : - Modified ReadReference(), ReadAttribute() and Dereference() to use XmlChar.GetPredefinedEntity(). - When returning entity reference, it checks extity declaration existence in certain conditions. - ReadAttribute() now skips general entity replacement on reading entity value. - ReadText() now handles whitespace texts as XmlNodeType.Whitespace. - ReadXmlDeclaration() holds isStandalone, which might be used in entity reference's well-formedness check. - internal 'DTD' now uses XmlParserContext.Dtd. - isInternalSubset was meaningless. Now uses input stack's Count. - Added some required SkipWhitespace(). - Several parameter entity handling changes. Added GetPEValue(name). TryExpandPERef() now uses ImportAsPERef(). ReadParameterEntityDecl() now uses its Resolve() when it was external PE. Now it uses value buffer instead of currentTag, to efficiently read (included) PE. CompileDeclaration() now uses ImportAsPERef instead of ExpandPERef(). ImportAsPERef() simply inserts the value to currentInput. ReadEntityDecl() also uses value buffer. Removed non-used methods. - Default attributes are now stored in normalized form. - Dereference() now considers non-expanding predefined entities. * XmlValidatingReader.cs : now holds Schemas, and ValidationType.Auto is more correctly supported. * XmlAttributeCollection.cs : When removing default attribute, it immediately inserts the attribute. RemoveAll() should consider default (not-removable) attributes. * XmlDocument.cs : Should have its default XmlResolver. Added Internal Resolver. Some Load() should use its XmlResolver. ImportNode() should copy its children in node level, not value level. It also have to consider not to copy default attribute on importing XmlElement. * XmlDocumentType.cs : Now uses document's XmlResolver to read DTD. * XmlAttribute.cs, XmlDocumentFragment.cs. XmlElement.cs : use XmlResolver on InnerXml. Removed some MonoTODO. * XmlNodeReader.cs : GetInternalParserConext() should provide its DTD. ResolveEntity() uses XmlResolver on entityReader. svn path=/trunk/mcs/; revision=17202
303 lines
7.9 KiB
C#
303 lines
7.9 KiB
C#
//
|
|
// System.Xml.XmlAttributeCollection
|
|
//
|
|
// Author:
|
|
// Jason Diamond ([email protected])
|
|
// Atsushi Enomoto ([email protected])
|
|
//
|
|
// (C) 2002 Jason Diamond http://injektilo.org/
|
|
// (C) 2002 Atsushi Enomoto
|
|
//
|
|
|
|
using System;
|
|
using System.Collections;
|
|
using Mono.Xml;
|
|
|
|
namespace System.Xml
|
|
{
|
|
public class XmlAttributeCollection : XmlNamedNodeMap, ICollection
|
|
{
|
|
XmlElement ownerElement;
|
|
XmlDocument ownerDocument;
|
|
|
|
internal XmlAttributeCollection (XmlNode parent) : base (parent)
|
|
{
|
|
ownerElement = parent as XmlElement;
|
|
ownerDocument = parent.OwnerDocument;
|
|
if(ownerElement == null)
|
|
throw new XmlException ("invalid construction for XmlAttributeCollection.");
|
|
}
|
|
|
|
bool ICollection.IsSynchronized {
|
|
get {
|
|
throw new NotImplementedException ();
|
|
}
|
|
}
|
|
|
|
bool IsReadOnly {
|
|
get {
|
|
return ownerElement.IsReadOnly;
|
|
}
|
|
}
|
|
|
|
[System.Runtime.CompilerServices.IndexerName ("ItemOf")]
|
|
public virtual XmlAttribute this [string name] {
|
|
get {
|
|
return (XmlAttribute) GetNamedItem (name);
|
|
}
|
|
}
|
|
|
|
[System.Runtime.CompilerServices.IndexerName ("ItemOf")]
|
|
public virtual XmlAttribute this [int i] {
|
|
get {
|
|
return (XmlAttribute) Nodes [i];
|
|
}
|
|
}
|
|
|
|
[System.Runtime.CompilerServices.IndexerName ("ItemOf")]
|
|
public virtual XmlAttribute this [string localName, string namespaceURI] {
|
|
get {
|
|
return (XmlAttribute) GetNamedItem (localName, namespaceURI);
|
|
}
|
|
}
|
|
|
|
object ICollection.SyncRoot {
|
|
get {
|
|
throw new NotImplementedException ();
|
|
}
|
|
}
|
|
|
|
|
|
public virtual XmlAttribute Append (XmlAttribute node)
|
|
{
|
|
XmlNode xmlNode = this.SetNamedItem (node);
|
|
return node;
|
|
}
|
|
|
|
public void CopyTo (XmlAttribute[] array, int index)
|
|
{
|
|
// assuming that Nodes is a correct collection.
|
|
for(int i=0; i<Nodes.Count; i++)
|
|
array [index + i] = Nodes [i] as XmlAttribute;
|
|
}
|
|
|
|
void ICollection.CopyTo (Array array, int index)
|
|
{
|
|
// assuming that Nodes is a correct collection.
|
|
array.CopyTo (Nodes.ToArray (typeof(XmlAttribute)), index);
|
|
}
|
|
|
|
public virtual XmlAttribute InsertAfter (XmlAttribute newNode, XmlAttribute refNode)
|
|
{
|
|
if(newNode.OwnerDocument != this.ownerDocument)
|
|
throw new ArgumentException ("different document created this newNode.");
|
|
|
|
ownerDocument.onNodeInserting (newNode, null);
|
|
|
|
int pos = Nodes.Count + 1;
|
|
if(refNode != null)
|
|
{
|
|
for(int i=0; i<Nodes.Count; i++)
|
|
{
|
|
XmlNode n = Nodes [i] as XmlNode;
|
|
if(n == refNode)
|
|
{
|
|
pos = i + 1;
|
|
break;
|
|
}
|
|
}
|
|
if(pos > Nodes.Count)
|
|
throw new XmlException ("refNode not found in this collection.");
|
|
}
|
|
else
|
|
pos = 0;
|
|
SetNamedItem (newNode, pos);
|
|
|
|
ownerDocument.onNodeInserted (newNode, null);
|
|
|
|
return newNode;
|
|
}
|
|
|
|
public virtual XmlAttribute InsertBefore (XmlAttribute newNode, XmlAttribute refNode)
|
|
{
|
|
if(newNode.OwnerDocument != ownerDocument)
|
|
throw new ArgumentException ("different document created this newNode.");
|
|
|
|
ownerDocument.onNodeInserting (newNode, null);
|
|
|
|
int pos = Nodes.Count;
|
|
if(refNode != null)
|
|
{
|
|
for(int i=0; i<Nodes.Count; i++)
|
|
{
|
|
XmlNode n = Nodes [i] as XmlNode;
|
|
if(n == refNode)
|
|
{
|
|
pos = i;
|
|
break;
|
|
}
|
|
}
|
|
if(pos == Nodes.Count)
|
|
throw new XmlException ("refNode not found in this collection.");
|
|
}
|
|
SetNamedItem (newNode, pos);
|
|
|
|
ownerDocument.onNodeInserted (newNode, null);
|
|
|
|
return newNode;
|
|
}
|
|
|
|
public virtual XmlAttribute Prepend (XmlAttribute node)
|
|
{
|
|
return this.InsertAfter (node, null);
|
|
}
|
|
|
|
public virtual XmlAttribute Remove (XmlAttribute node)
|
|
{
|
|
if (node == null)
|
|
throw new ArgumentException ("Specified node is null.");
|
|
if (node.OwnerDocument != ownerDocument)
|
|
throw new ArgumentException ("Specified node is in a different document.");
|
|
|
|
XmlAttribute retAttr = null;
|
|
foreach (XmlAttribute attr in Nodes) {
|
|
if (attr == node) {
|
|
retAttr = attr;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if(retAttr != null) {
|
|
ownerDocument.onNodeRemoving (node, null);
|
|
base.RemoveNamedItem (retAttr.LocalName, retAttr.NamespaceURI);
|
|
RemoveIdenticalAttribute (retAttr);
|
|
ownerDocument.onNodeRemoved (node, null);
|
|
}
|
|
// If it is default, then directly create new attribute.
|
|
if (!retAttr.Specified) {
|
|
XmlAttribute attr = ownerDocument.CreateAttribute (retAttr.Prefix,
|
|
retAttr.LocalName, retAttr.NamespaceURI);
|
|
attr.SetDefault ();
|
|
foreach (XmlNode child in retAttr.ChildNodes)
|
|
attr.AppendChild (child);
|
|
this.SetNamedItem (attr);
|
|
}
|
|
return retAttr;
|
|
}
|
|
|
|
public virtual void RemoveAll ()
|
|
{
|
|
int current = 0;
|
|
while (current < Count) {
|
|
XmlAttribute attr = this [current];
|
|
if (!attr.Specified)
|
|
current++;
|
|
// It is called for the purpose of event support.
|
|
Remove (attr);
|
|
}
|
|
}
|
|
|
|
public virtual XmlAttribute RemoveAt (int i)
|
|
{
|
|
if(Nodes.Count <= i)
|
|
return null;
|
|
return Remove ((XmlAttribute)Nodes [i]);
|
|
}
|
|
|
|
public override XmlNode SetNamedItem (XmlNode node)
|
|
{
|
|
if(IsReadOnly)
|
|
throw new XmlException ("this AttributeCollection is read only.");
|
|
|
|
return AdjustIdenticalAttributes (node as XmlAttribute, base.SetNamedItem (node, -1) as XmlAttribute);
|
|
}
|
|
|
|
internal void AddIdenticalAttribute ()
|
|
{
|
|
SetIdenticalAttribute (false);
|
|
}
|
|
|
|
internal void RemoveIdenticalAttribute ()
|
|
{
|
|
SetIdenticalAttribute (true);
|
|
}
|
|
|
|
private void SetIdenticalAttribute (bool remove)
|
|
{
|
|
if (ownerElement == null)
|
|
return;
|
|
|
|
// Check if new attribute's datatype is ID.
|
|
XmlDocumentType doctype = ownerDocument.DocumentType;
|
|
if (doctype == null || doctype.DTD == null)
|
|
return;
|
|
DTDElementDeclaration elem = doctype.DTD.ElementDecls [ownerElement.Name];
|
|
foreach (XmlAttribute node in this) {
|
|
DTDAttributeDefinition attdef = elem == null ? null : elem.Attributes [node.Name];
|
|
if (attdef == null || attdef.Datatype.TokenizedType != XmlTokenizedType.ID)
|
|
continue;
|
|
|
|
if (remove) {
|
|
if (ownerDocument.GetIdenticalAttribute (node.Value) != null) {
|
|
ownerDocument.RemoveIdenticalAttribute (node.Value);
|
|
return;
|
|
}
|
|
} else {
|
|
// adding new identical attribute, but
|
|
// MS.NET is pity for ID support, so I'm wondering how to correct it...
|
|
if (ownerDocument.GetIdenticalAttribute (node.Value) != null)
|
|
throw new XmlException (String.Format (
|
|
"ID value {0} already exists in this document.", node.Value));
|
|
ownerDocument.AddIdenticalAttribute (node);
|
|
return;
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
private XmlNode AdjustIdenticalAttributes (XmlNode node, XmlNode existing)
|
|
{
|
|
// If owner element is not appended to the document,
|
|
// ID table should not be filled.
|
|
if (ownerElement == null)
|
|
return existing;
|
|
|
|
RemoveIdenticalAttribute (existing);
|
|
|
|
// Check if new attribute's datatype is ID.
|
|
XmlDocumentType doctype = node.OwnerDocument.DocumentType;
|
|
if (doctype == null || doctype.DTD == null)
|
|
return existing;
|
|
DTDAttListDeclaration attList = doctype.DTD.AttListDecls [ownerElement.Name];
|
|
DTDAttributeDefinition attdef = attList == null ? null : attList.Get (node.Name);
|
|
if (attdef == null || attdef.Datatype.TokenizedType != XmlTokenizedType.ID)
|
|
return existing;
|
|
|
|
// adding new identical attribute, but
|
|
// MS.NET is pity for ID support, so I'm wondering how to correct it...
|
|
if (ownerDocument.GetIdenticalAttribute (node.Value) != null)
|
|
throw new XmlException (String.Format (
|
|
"ID value {0} already exists in this document.", node.Value));
|
|
ownerDocument.AddIdenticalAttribute (node as XmlAttribute);
|
|
|
|
return existing;
|
|
}
|
|
|
|
private XmlNode RemoveIdenticalAttribute (XmlNode existing)
|
|
{
|
|
// If owner element is not appended to the document,
|
|
// ID table should not be filled.
|
|
if (ownerElement == null)
|
|
return existing;
|
|
|
|
if (existing != null) {
|
|
// remove identical attribute (if it is).
|
|
if (ownerDocument.GetIdenticalAttribute (existing.Value) != null)
|
|
ownerDocument.RemoveIdenticalAttribute (existing.Value);
|
|
}
|
|
|
|
return existing;
|
|
}
|
|
}
|
|
}
|