diff options
Diffstat (limited to 'mcs')
25 files changed, 421 insertions, 161 deletions
diff --git a/mcs/class/System.XML/ChangeLog b/mcs/class/System.XML/ChangeLog index 3e5e8d19234..07e12744f95 100644 --- a/mcs/class/System.XML/ChangeLog +++ b/mcs/class/System.XML/ChangeLog @@ -1,3 +1,12 @@ +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * System.Xml_test.dll.sources : added XmlSchemaTypeTests.cs. + +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * System.Xml_test.dll.sources : XmlSchemaDatatypeTests.cs was missing. + collected sys.xml.schema lines. + 2005-12-28 Gert Driesen <drieseng@users.sourceforge.net> * System.Xml_test.dll.sources: Added XmlSchemaExporterTests.cs. diff --git a/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog b/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog index 5bda8228106..a7074156a40 100644 --- a/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog @@ -1,3 +1,9 @@ +2006-01-11 Atsushi Enomoto <atsushi@ximian.com> + + * XmlSchemaValidatingReader.cs : removed unused constructors. + Now it implements IXmlSchemaInfo. Use XmlSchemaType instead of + Object to represent schema types. + 2006-01-06 Atsushi Enomoto <atsushi@ximian.com> * XsdValidatingReader.cs : diff --git a/mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs b/mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs index 42d2c23cca5..d887625f9ad 100644 --- a/mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs +++ b/mcs/class/System.XML/Mono.Xml.Schema/XmlSchemaValidatingReader.cs @@ -76,7 +76,8 @@ using ValException = System.Xml.Schema.XmlSchemaValidationException; namespace Mono.Xml.Schema { - internal class XmlSchemaValidatingReader : XmlReader, IXmlLineInfo + internal class XmlSchemaValidatingReader : XmlReader, IXmlLineInfo, + IXmlSchemaInfo { static readonly XsAttr [] emptyAttributeArray = new XsAttr [0]; @@ -91,7 +92,6 @@ namespace Mono.Xml.Schema IXmlLineInfo readerLineInfo; ValidationType validationType; IXmlNamespaceResolver nsResolver; -// IHasXmlSchemaInfo sourceReaderSchemaInfo; int startDepth; StringBuilder tmpBuilder = new StringBuilder (); @@ -100,48 +100,14 @@ namespace Mono.Xml.Schema int currentDefaultAttribute = -1; ArrayList defaultAttributesCache = new ArrayList (); bool defaultAttributeConsumed; - object currentAttrType; + XmlSchemaType currentAttrType; // Extra for XmlSchemaValidtingReader // (not in XsdValidatingReader) XsElement element; // ... xsinfo.Element? - object xsiType; // ... xsinfo.SchemaType? #endregion - public XmlSchemaValidatingReader (XmlReader reader, XmlSchemaSet schemas) - { - nsResolver = reader as IXmlNamespaceResolver; - if (nsResolver == null) - throw new ArgumentException ("Argument XmlReader must implement IXmlNamespaceResolver."); - options = ValidationFlags.ReportValidationWarnings - | ValidationFlags.ProcessSchemaLocation - | ValidationFlags.ProcessInlineSchema; - - this.reader = reader; - if (schemas == null) - schemas = new XmlSchemaSet (); - v = new XmlSchemaValidator ( - reader.NameTable, - schemas, - nsResolver, - options); - - readerLineInfo = reader as IXmlLineInfo; - startDepth = reader.Depth; - getter = delegate () { return Value; }; - xsinfo = new XmlSchemaInfo (); // transition cache - v.LineInfoProvider = this; - v.ValidationEventSender = reader; -#if !NON_MONO - v.XmlResolver = schemas.XmlResolver; -#else - v.XmlResolver = new XmlUrlResolver (); -#endif - v.SourceUri = new Uri (null, reader.BaseURI); // FIXME: it is in fact not in MS.NET. - v.Initialize (); - } - public XmlSchemaValidatingReader (XmlReader reader, XmlReaderSettings settings) { @@ -164,6 +130,7 @@ namespace Mono.Xml.Schema readerLineInfo = reader as IXmlLineInfo; startDepth = reader.Depth; getter = delegate () { return Value; }; + xsinfo = new XmlSchemaInfo (); // transition cache v.LineInfoProvider = this; v.ValidationEventSender = reader; #if !NON_MONO @@ -177,48 +144,11 @@ namespace Mono.Xml.Schema v.Initialize (); } - public XmlSchemaValidatingReader ( - XPathNavigator navigator, - XmlSchemaSet schemas, - ValidationEventHandler handler) - { - this.reader = navigator.ReadSubtree (); - startDepth = reader.Depth; - IXmlSchemaInfo info = navigator.SchemaInfo; - SchemaType schemaType = info != null ? - info.SchemaType : null; - - if (schemas == null && schemaType == null) - throw new ArgumentException ("Neither of XmlSchemaSet is specified, nor XPathNavigator does not provide schema type information on current node."); - - if (schemas == null) - schemas = new XmlSchemaSet (reader.NameTable); - - v = new XmlSchemaValidator ( - navigator.NameTable, - schemas, - navigator, - ValidationFlags.ProcessIdentityConstraints); - - readerLineInfo = navigator as IXmlLineInfo; - getter = delegate () { return Value; }; - v.LineInfoProvider = this; - v.ValidationEventSender = navigator; -#if !NON_MONO - v.XmlResolver = schemas.XmlResolver; -#else - v.XmlResolver = new XmlUrlResolver (); -#endif - v.Initialize (schemaType); - } - public ValidationEventHandler ValidationEventHandler; - public object ActualType { + public XmlSchemaType ElementSchemaType { get { - return xsiType != null ? - xsiType : - element != null ? element.ElementType : null; + return element != null ? element.ElementSchemaType : null; } } @@ -242,24 +172,24 @@ namespace Mono.Xml.Schema get { return readerLineInfo != null ? readerLineInfo.LinePosition : 0; } } - public object SchemaType { + public XmlSchemaType SchemaType { get { if (ReadState != ReadState.Interactive) return null; switch (NodeType) { case XmlNodeType.Element: - if (ActualType != null) - return ActualType; + if (ElementSchemaType != null) + return ElementSchemaType; else return null;//SourceReaderSchemaType; case XmlNodeType.Attribute: if (currentAttrType == null) { - ComplexType ct = ActualType as ComplexType; + ComplexType ct = ElementSchemaType as ComplexType; if (ct != null) { XsAttr attdef = ct.AttributeUses [new XmlQualifiedName (LocalName, NamespaceURI)] as XsAttr; if (attdef != null) - currentAttrType = attdef.AttributeType; + currentAttrType = attdef.AttributeSchemaType; return currentAttrType; } // currentAttrType = SourceReaderSchemaType; @@ -450,7 +380,7 @@ namespace Mono.Xml.Schema } public override IXmlSchemaInfo SchemaInfo { - get { return xsinfo; } + get { return this; } } public override string Value { @@ -855,6 +785,30 @@ namespace Mono.Xml.Schema } #endregion + + #region IXmlSchemaInfo + + public bool IsNil { + get { return xsinfo.IsNil; } + } + + public XmlSchemaSimpleType MemberType { + get { return xsinfo.MemberType; } + } + + public XmlSchemaAttribute SchemaAttribute { + get { return xsinfo.SchemaAttribute; } + } + + public XmlSchemaElement SchemaElement { + get { return xsinfo.SchemaElement; } + } + + public XmlSchemaValidity Validity { + get { return xsinfo.Validity; } + } + + #endregion } } diff --git a/mcs/class/System.XML/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/System.Xml.Schema/ChangeLog index 17cefced3de..9a53330afbe 100644 --- a/mcs/class/System.XML/System.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/System.Xml.Schema/ChangeLog @@ -1,3 +1,18 @@ +2006-01-11 Atsushi Enomoto <atsushi@ximian.com> + + * XmlSchemaAttribute.cs, XmlSchemaElement.cs : AttributeSchemaType + and ElementSchemaType were not working fine for anySimpleType. + * XmlSchemaValidator.cs : When actual schema type was complex, + schema types was not filled correctly. Modified some extra comments. + * XmlSchemaSet.cs, XmlSchemaType.cs : removed extra MonoTODOs. + +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * XmlAtomicValue.cs : it won't be implemented since there is no way + to test it inside sys.xml. Thus remarked MonoTODO. + * XmlSchemaDatatype.cs : implemented IsDerivedFrom(), which is however + mostly useless. + 2006-01-06 Atsushi Enomoto <atsushi@ximian.com> * XmlSchemaSet.cs : Add() rollbacks IsCompiled to false. diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlAtomicValue.cs b/mcs/class/System.XML/System.Xml.Schema/XmlAtomicValue.cs index 65616cf782f..a543e74db95 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlAtomicValue.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlAtomicValue.cs @@ -36,6 +36,7 @@ using System.Xml.XPath; namespace System.Xml.Schema { + [MonoTODO ("This class is unused and thus won't be finished.")] public sealed class XmlAtomicValue : XPathItem, ICloneable { bool booleanValue; @@ -53,7 +54,6 @@ namespace System.Xml.Schema #region Constructors - [MonoTODO] internal XmlAtomicValue (bool value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -68,7 +68,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (DateTime value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -83,7 +82,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (decimal value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -98,7 +96,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (double value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -113,7 +110,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (int value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -128,7 +124,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (long value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -143,7 +138,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (float value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -158,7 +152,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (string value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -175,7 +168,6 @@ namespace System.Xml.Schema schemaType = xmlType; } - [MonoTODO] internal XmlAtomicValue (object value, XmlSchemaType xmlType) { Init (value, xmlType); @@ -281,13 +273,11 @@ namespace System.Xml.Schema return this.Clone (); } - [MonoTODO] public XmlAtomicValue Clone () { return new XmlAtomicValue (this, schemaType); } - [MonoTODO] public override object ValueAs (Type type, IXmlNamespaceResolver nsResolver) { switch (XmlTypeCodeFromRuntimeType (type, false)) { @@ -338,7 +328,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override object TypedValue { get { switch (ResolvedTypeCode) { @@ -360,7 +349,6 @@ namespace System.Xml.Schema } } - [MonoTODO] // This method works like ValueAsString. public override string Value { get { @@ -425,7 +413,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override bool ValueAsBoolean { get { switch (xmlTypeCode) { @@ -457,7 +444,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override DateTime ValueAsDateTime { get { switch (xmlTypeCode) { @@ -478,7 +464,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override double ValueAsDouble { get { switch (xmlTypeCode) { @@ -509,7 +494,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override int ValueAsInt { get { switch (xmlTypeCode) { @@ -540,7 +524,6 @@ namespace System.Xml.Schema } } - [MonoTODO] public override long ValueAsLong { get { switch (xmlTypeCode) { @@ -571,12 +554,10 @@ namespace System.Xml.Schema } } - [MonoTODO] public override Type ValueType { get { return schemaType.Datatype.ValueType; } } - [MonoTODO] public override XmlSchemaType XmlType { get { return schemaType; } } diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs index 04ce21971ae..b4b50820589 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaAttribute.cs @@ -448,9 +448,13 @@ namespace System.Xml.Schema validatedUse = Use;
#if NET_2_0
- attributeSchemaType = attributeType as XmlSchemaSimpleType;
- if (attributeSchemaType == null)
- attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType (((XmlSchemaDatatype) attributeType).TypeCode);
+ if (attributeType != null) {
+ attributeSchemaType = attributeType as XmlSchemaSimpleType;
+ if (attributeType == XmlSchemaSimpleType.AnySimpleType)
+ attributeSchemaType = XmlSchemaSimpleType.XsAnySimpleType;
+ if (attributeSchemaType == null)
+ attributeSchemaType = XmlSchemaType.GetBuiltInSimpleType (SchemaTypeName);
+ }
#endif
ValidationId = schema.ValidationId;
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaDatatype.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaDatatype.cs index ca7f8db7c2f..751560d988b 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaDatatype.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaDatatype.cs @@ -79,10 +79,12 @@ namespace System.Xml.Schema throw new NotImplementedException ();
}
- [MonoTODO]
public virtual bool IsDerivedFrom (XmlSchemaDatatype datatype)
{
- throw new NotImplementedException ();
+ // It is documented to return always false, but
+ // actually returns true when the argument is for
+ // the same type (and it does not check null argument).
+ return this == datatype;
}
#endif
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs index 1eaeb7bd400..86283db4e24 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaElement.cs @@ -743,9 +743,13 @@ namespace System.Xml.Schema ident.Validate (h, schema);
#if NET_2_0
- elementSchemaType = elementType as XmlSchemaType;
- if (elementSchemaType == null && elementType != null)
- elementSchemaType = XmlSchemaType.GetBuiltInType (((XmlSchemaDatatype) elementType).TypeCode);
+ if (elementType != null) {
+ elementSchemaType = elementType as XmlSchemaType;
+ if (elementType == XmlSchemaSimpleType.AnySimpleType)
+ elementSchemaType = XmlSchemaSimpleType.XsAnySimpleType;
+ if (elementSchemaType == null)
+ elementSchemaType = XmlSchemaType.GetBuiltInSimpleType (SchemaTypeName);
+ }
#endif
ValidationId = schema.ValidationId;
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs index 76561d2deec..6c9eca9bcc6 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs @@ -181,7 +181,6 @@ namespace System.Xml.Schema Add (schema); } - [MonoTODO ("We need to research more about the expected behavior")] public XmlSchema Add (XmlSchema schema) { schemas.Add (schema); diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaType.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaType.cs index 45b07fc3e1a..0ce5b5f87ae 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaType.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaType.cs @@ -134,7 +134,6 @@ namespace System.Xml.Schema }
#if NET_2_0
- [MonoTODO]
// LAMESPEC: for IDREFS it returns Idref. for ENTITIES
// it returns Entity. for NMTOKENS it returns NmToken.
[XmlIgnore]
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs index d5702d2445f..1790c478aa8 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs @@ -181,11 +181,8 @@ namespace System.Xml.Schema set { xmlResolver = value; } } - [MonoTODO] public Uri SourceUri { get { return sourceUri; } - // FIXME: actually there seems no setter, but then - // it will never make sense. set { sourceUri = value; } } #endregion @@ -791,7 +788,7 @@ namespace System.Xml.Schema object parsedValue = null; try { parsedValue = getter (); - } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError ("Attribute value is invalid against its data type " + dt.TokenizedType, ex); } XmlSchemaType type = info != null ? info.SchemaType : null; @@ -937,8 +934,8 @@ namespace System.Xml.Schema if (info != null) { info.IsNil = xsiNilDepth >= 0; info.SchemaElement = null; - info.SchemaType = st; - if (st == null) + info.SchemaType = Context.ActualType as XmlSchemaType; + if (info.SchemaType == null) info.SchemaType = XmlSchemaType.GetBuiltInSimpleType (dt.TypeCode); info.SchemaAttribute = null; info.IsDefault = false; // FIXME: might be true @@ -981,7 +978,7 @@ namespace System.Xml.Schema if (itemDatatype != null) { try { retValues [vi] = itemDatatype.ParseValue (each, nameTable, nsResolver); - } catch (Exception ex) { // FIXME: (wishlist) better exception handling ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError ("List type value contains one or more invalid values.", ex); break; } @@ -1003,7 +1000,7 @@ namespace System.Xml.Schema if (itemDatatype != null) { try { ret = itemDatatype.ParseValue (each, nameTable, nsResolver); - } catch (Exception) { // FIXME: (wishlist) better exception handling ;-( + } catch (Exception) { // It is inevitable and bad manner. continue; } } @@ -1048,7 +1045,7 @@ namespace System.Xml.Schema if (validatedDatatype != null) { try { ret = validatedDatatype.ParseValue (value, nameTable, nsResolver); - } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError (String.Format ("Invalidly typed data was specified."), ex); } } @@ -1232,7 +1229,7 @@ namespace System.Xml.Schema if (dt != null) { try { identity = dt.ParseValue (value, nameTable, nsResolver); - } catch (Exception ex) { // FIXME: (wishlist) This is bad manner ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError ("Identity value is invalid against its data type " + dt.TokenizedType, ex); } } @@ -1394,7 +1391,7 @@ namespace System.Xml.Schema for (int i = 0; i < tmp.Length; i += 2) { try { schema = ReadExternalSchema (tmp [i + 1]); - } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError ("Could not resolve schema location URI: " + schemaLocation, ex, true); continue; } @@ -1423,7 +1420,7 @@ namespace System.Xml.Schema try { schema = ReadExternalSchema (noNsSchemaLocation); - } catch (Exception ex) { // FIXME: (wishlist) It is bad manner ;-( + } catch (Exception ex) { // It is inevitable and bad manner. HandleError ("Could not resolve schema location URI: " + noNsSchemaLocation, ex, true); } if (schema != null && schema.TargetNamespace != null) diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog index c7d7c295879..a2498bf3d6c 100644 --- a/mcs/class/System.XML/System.Xml/ChangeLog +++ b/mcs/class/System.XML/System.Xml/ChangeLog @@ -1,3 +1,28 @@ +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlTextWriter.cs : Do not local duplicate of automatically-created + prefixes (i.e. check local autocreated prefixes other than + namespaces from ancestors). Fixed bug #77086 and #77087. + +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlWriter.cs : use XmlChar.IsNmToken() to check argument and throw + ArgumentException in WriteNmTokenInternal(). + +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlTextWriter.cs : Fixed bug #77094. Only XmlTextWriter checks + such invalid "xml" prefix which is being mapped to different + namespace URI than the predefined one. + Removed comment that does not make sense. + * XmlNamespaceManager.cs : IsValidDeclaration() could be private. + Added some comments. + +2006-01-11 Atsushi Enomoto <atsushi@ximian.com> + + * DTDObjectModel.cs : dtd2xsd fix; set use="optional" when an + attribute is #IMPLIED. + 2006-01-06 Atsushi Enomoto <atsushi@ximian.com> * XmlWriter.cs : In WriteNode(XPathNavigator, bool), Avoid diff --git a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs index e411b8fa08d..bae72caa7ba 100644 --- a/mcs/class/System.XML/System.Xml/DTDObjectModel.cs +++ b/mcs/class/System.XML/System.Xml/DTDObjectModel.cs @@ -833,6 +833,8 @@ namespace Mono.Xml SetLineInfo (a); a.Name = Name; a.DefaultValue = resolvedNormalizedDefaultValue; + if (OccurenceType != DTDAttributeOccurenceType.Required) + a.Use = XmlSchemaUse.Optional; XmlQualifiedName qname = XmlQualifiedName.Empty; ArrayList enumeration = null; diff --git a/mcs/class/System.XML/System.Xml/XmlNamespaceManager.cs b/mcs/class/System.XML/System.Xml/XmlNamespaceManager.cs index ea6a8b50523..29afff1e604 100644 --- a/mcs/class/System.XML/System.Xml/XmlNamespaceManager.cs +++ b/mcs/class/System.XML/System.Xml/XmlNamespaceManager.cs @@ -170,9 +170,11 @@ namespace System.Xml decls [declPos].Uri = uri; } - internal static string IsValidDeclaration (string prefix, string uri, bool throwException) + static string IsValidDeclaration (string prefix, string uri, bool throwException) { string message = null; + // It is funky, but it does not check whether prefix + // is equivalent to "xml" in case-insensitive means. if (prefix == PrefixXml && uri != XmlnsXml) message = String.Format ("Prefix \"xml\" can only be bound to the fixed namespace URI \"{0}\". \"{1}\" is invalid.", XmlnsXml, uri); else if (message == null && prefix == "xmlns") diff --git a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs index cc86640a281..061d259b364 100644 --- a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs +++ b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs @@ -752,8 +752,6 @@ openElements [openElementCount - 1]).IndentingOverriden; public override void WriteStartAttribute (string prefix, string localName, string ns) { if (prefix == "xml") { - // MS.NET looks to allow other names than - // lang and space (e.g. xml:link, xml:hack). ns = XmlNamespaceManager.XmlnsXml; if (localName == "lang") openXmlLang = true; @@ -799,7 +797,7 @@ openElements [openElementCount - 1]).IndentingOverriden; string formatPrefix = ""; if (ns != String.Empty && prefix != "xmlns") { - string existingPrefix = namespaceManager.LookupPrefix (ns, false); + string existingPrefix = GetExistingPrefix (ns); if (existingPrefix == null || existingPrefix == "") { bool createPrefix = false; @@ -854,6 +852,15 @@ openElements [openElementCount - 1]).IndentingOverriden; } } + string GetExistingPrefix (string ns) + { + if (newAttributeNamespaces.ContainsValue (ns)) + foreach (DictionaryEntry de in newAttributeNamespaces) + if (de.Value as string == ns) + return (string) de.Key; + return namespaceManager.LookupPrefix (ns, false); + } + private string CheckNewPrefix (bool createPrefix, string prefix, string ns) { do { @@ -916,6 +923,14 @@ openElements [openElementCount - 1]).IndentingOverriden; if ((prefix != null && prefix.Length > 0) && ((ns == null))) throw ArgumentError ("Cannot use a prefix with an empty namespace."); + // Considering the fact that WriteStartAttribute() + // automatically changes argument namespaceURI, this + // is kind of silly implementation. See bug #77094. + if (Namespaces && + ns != XmlNamespaceManager.XmlnsXml && + String.Compare (prefix, "xml", true) == 0) + throw new ArgumentException ("A prefix cannot be equivalent to \"xml\" in case-insensitive match."); + // ignore non-namespaced node's prefix. if (ns == null || ns == String.Empty) prefix = String.Empty; diff --git a/mcs/class/System.XML/System.Xml/XmlWriter.cs b/mcs/class/System.XML/System.Xml/XmlWriter.cs index 3870f7e7df6..0010ce4c0da 100644 --- a/mcs/class/System.XML/System.Xml/XmlWriter.cs +++ b/mcs/class/System.XML/System.Xml/XmlWriter.cs @@ -360,16 +360,19 @@ namespace System.Xml internal virtual void WriteNmTokenInternal (string name) { + bool valid = true; #if NET_2_0 switch (Settings.ConformanceLevel) { case ConformanceLevel.Document: case ConformanceLevel.Fragment: - XmlConvert.VerifyNMTOKEN (name); - break; + valid = XmlChar.IsNmToken (name); + break; } #else - XmlConvert.VerifyNMTOKEN (name); + valid = XmlChar.IsNmToken (name); #endif + if (!valid) + throw new ArgumentException ("Argument name is not a valid NMTOKEN."); WriteString (name); } diff --git a/mcs/class/System.XML/System.Xml_test.dll.sources b/mcs/class/System.XML/System.Xml_test.dll.sources index e1f968d3e0b..58842945d46 100644 --- a/mcs/class/System.XML/System.Xml_test.dll.sources +++ b/mcs/class/System.XML/System.Xml_test.dll.sources @@ -44,9 +44,13 @@ System.Xml/nist_dom/fundamental/Element/Element.cs System.Xml/nist_dom/fundamental/NamedNodeMap/NamedNodeMap.cs System.Xml/nist_dom/fundamental/NodeList/NodeList.cs System.Xml/nist_dom/fundamental/Text/Text.cs +System.Xml.Schema/XmlSchemaAssertion.cs +System.Xml.Schema/XmlSchemaBuiltInDatatypeTests.cs +System.Xml.Schema/XmlSchemaDatatypeTests.cs +System.Xml.Schema/XmlSchemaLengthFacetTests.cs System.Xml.Schema/XmlSchemaTests.cs +System.Xml.Schema/XmlSchemaTypeTests.cs System.Xml.Schema/XmlSchemaSetTests.cs -System.Xml.Schema/XmlSchemaLengthFacetTests.cs System.Xml.Serialization/ComplexDataStructure.cs System.Xml.Serialization/DeserializeTests.cs System.Xml.Serialization/SoapAttributeAttributeTests.cs @@ -70,8 +74,6 @@ System.Xml.Serialization/XmlSchemaExporterTests.cs System.Xml.Serialization/XmlSerializationWriterTests.cs System.Xml.Serialization/XmlTextAttributeTests.cs System.Xml.Serialization/XmlTypeAttributeTests.cs -System.Xml.Schema/XmlSchemaAssertion.cs -System.Xml.Schema/XmlSchemaBuiltInDatatypeTests.cs System.Xml.Serialization/XmlSerializerTests.cs System.Xml.Serialization/XmlSerializerTestClasses.cs System.Xml.XPath/SelectNodesTests.cs diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog index b40a0c2b464..2f486b9cb16 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog @@ -1,3 +1,17 @@ +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * XmlSchemaTypeTests.cs : new file. Test for TypeCode. + * XmlSchemaSetTests.cs : added more tests for Add() and marked one as + NotWorking (we need info on how consistent this method is). + +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * XmlSchemaDatatypeTests.cs : oops sys.col.generic is NET_2_0. + +2006-01-10 Atsushi Enomoto <atsushi@ximian.com> + + * XmlSchemaDatatypeTests.cs : added test for 2.0 IsDerivedFrom(). + 2006-01-06 Atsushi Enomoto <atsushi@ximian.com> * XmlSchemaSetTests.cs : added AddRollbackIsCompiled(); Add() changes diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaDatatypeTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaDatatypeTests.cs index a0d23a0ea61..e7420bf4a67 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaDatatypeTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaDatatypeTests.cs @@ -11,8 +11,16 @@ using System; using System.IO; using System.Xml; using System.Xml.Schema; +#if NET_2_0 +using System.Collections.Generic; +#endif using NUnit.Framework; +using QName = System.Xml.XmlQualifiedName; +using SimpleType = System.Xml.Schema.XmlSchemaSimpleType; +using SimpleRest = System.Xml.Schema.XmlSchemaSimpleTypeRestriction; +using AssertType = NUnit.Framework.Assert; + namespace MonoTests.System.Xml { [TestFixture] @@ -39,6 +47,7 @@ namespace MonoTests.System.Xml } [Test] + [Category ("NotWorking")] // ContentTypeParticle impl. difference. public void TestAnyType () { XmlSchema schema = GetSchema ("Test/XmlFiles/xsd/datatypesTest.xsd"); @@ -71,5 +80,80 @@ namespace MonoTests.System.Xml // AssertDatatype (schema, 6, XmlTokenizedType.NMTOKEN, typeof (string []), "f o o", new string [] {"f", "o", "o"}); } +#if NET_2_0 + string [] allTypes = new string [] { + "string", "boolean", "float", "double", "decimal", + "duration", "dateTime", "time", "date", "gYearMonth", + "gYear", "gMonthDay", "gDay", "gMonth", "hexBinary", + "base64Binary", "anyURI", "QName", "NOTATION", + "normalizedString", "token", "language", "IDREFS", + "ENTITIES", "NMTOKEN", "NMTOKENS", "Name", "NCName", + "ID", "IDREF", "ENTITY", "integer", + "nonPositiveInteger", "negativeInteger", "long", + "int", "short", "byte", "nonNegativeInteger", + "unsignedLong", "unsignedInt", "unsignedShort", + "unsignedByte", "positiveInteger" + }; + + XmlSchemaSet allWrappers; + + void SetupSimpleTypeWrappers () + { + XmlSchema schema = new XmlSchema (); + List<QName> qnames = new List<QName> (); + foreach (string name in allTypes) { + SimpleType st = new SimpleType (); + st.Name = "x-" + name; + SimpleRest r = new SimpleRest (); + st.Content = r; + QName qname = new QName (name, XmlSchema.Namespace); + r.BaseTypeName = qname; + qnames.Add (qname); + schema.Items.Add (st); + } + XmlSchemaSet sset = new XmlSchemaSet (); + sset.Add (schema); + sset.Compile (); + allWrappers = sset; + } + + XmlSchemaDatatype GetDatatype (string name) + { + return (allWrappers.GlobalTypes [new QName ("x-" + name, + String.Empty)] as SimpleType).Datatype; + } + + string [] GetDerived (string target) + { + XmlSchemaDatatype strType = GetDatatype (target); + List<string> results = new List<string> (); + foreach (string name in allTypes) { + if (name == target) + continue; + XmlSchemaDatatype deriv = GetDatatype (name); + if (deriv.IsDerivedFrom (strType)) + results.Add (name); + else Console.Error.WriteLine (deriv.GetType () + " is not derived from " + strType.GetType ()); + } + return results.ToArray (); + } + + [Test] + public void IsDerivedFrom () + { + SetupSimpleTypeWrappers (); + + // Funky, but XmlSchemaDatatype.IsDerivedFrom() is + // documented to always return false, but actually + // matches the same type - which could be guessed that + // this method is used only to detect user-defined + // simpleType derivation. + foreach (string b in allTypes) + foreach (string d in allTypes) + AssertType.AreEqual (b == d, GetDatatype (d).IsDerivedFrom (GetDatatype (b)), b); + + AssertType.IsFalse (GetDatatype ("string").IsDerivedFrom (null), "null arg"); + } +#endif } } diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs index 56a066c6760..20ad97f68b2 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs @@ -56,9 +56,22 @@ namespace MonoTests.System.Xml } [Test] - [Ignore ("This behavior might be changed, since Add(XmlSchema) does not throw any exceptions, while this does.")] + public void AddSchemaThenReader () + { + XmlSchemaSet ss = new XmlSchemaSet (); + XmlDocument doc = new XmlDocument (); + doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' />"); + XmlSchema xs = new XmlSchema (); + xs.TargetNamespace = "ab"; + ss.Add (xs); + ss.Add ("ab", new XmlNodeReader (doc)); + } + + [Test] + [Category ("NotWorking")] // How can we differentiate this + // case and the testcase above? [ExpectedException (typeof (ArgumentException))] - public void AddTwice () + public void AddReaderTwice () { XmlSchemaSet ss = new XmlSchemaSet (); XmlDocument doc = new XmlDocument (); @@ -68,6 +81,16 @@ namespace MonoTests.System.Xml } [Test] + public void AddSchemaTwice () + { + XmlSchemaSet ss = new XmlSchemaSet (); + XmlDocument doc = new XmlDocument (); + doc.LoadXml ("<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='urn:ab' />"); + ss.Add (XmlSchema.Read (new XmlNodeReader (doc), null)); + ss.Add (XmlSchema.Read (new XmlNodeReader (doc), null)); + } + + [Test] public void CompilationSettings () { Assert.IsNotNull (new XmlSchemaSet ().CompilationSettings); diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTypeTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTypeTests.cs new file mode 100644 index 00000000000..f97b6bddc44 --- /dev/null +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTypeTests.cs @@ -0,0 +1,101 @@ +// +// System.Xml.XmlSchemaSetTests.cs +// +// Author: +// Atsushi Enomoto <atsushi@ximian.com> +// +// (C) 2004 Novell Inc. +// + +using System; +using System.Collections; +using System.IO; +using System.Xml; +using System.Xml.Schema; +using NUnit.Framework; + +using QName = System.Xml.XmlQualifiedName; +using SimpleType = System.Xml.Schema.XmlSchemaSimpleType; +using SimpleRest = System.Xml.Schema.XmlSchemaSimpleTypeRestriction; +using AssertType = NUnit.Framework.Assert; + +namespace MonoTests.System.Xml +{ + [TestFixture] + public class XmlSchemaTypeTests + { +#if NET_2_0 + string [] all_types = new string [] { + "string", "boolean", "float", "double", "decimal", + "duration", "dateTime", "time", "date", "gYearMonth", + "gYear", "gMonthDay", "gDay", "gMonth", "hexBinary", + "base64Binary", "anyURI", "QName", "NOTATION", + "normalizedString", "token", "language", "IDREFS", + "ENTITIES", "NMTOKEN", "NMTOKENS", "Name", "NCName", + "ID", "IDREF", "ENTITY", "integer", + "nonPositiveInteger", "negativeInteger", "long", + "int", "short", "byte", "nonNegativeInteger", + "unsignedLong", "unsignedInt", "unsignedShort", + "unsignedByte", "positiveInteger" + }; + + XmlTypeCode [] type_codes = new XmlTypeCode [] { + XmlTypeCode.String, + XmlTypeCode.Boolean, + XmlTypeCode.Float, + XmlTypeCode.Double, + XmlTypeCode.Decimal, + XmlTypeCode.Duration, + XmlTypeCode.DateTime, + XmlTypeCode.Time, + XmlTypeCode.Date, + XmlTypeCode.GYearMonth, + XmlTypeCode.GYear, + XmlTypeCode.GMonthDay, + XmlTypeCode.GDay, + XmlTypeCode.GMonth, + XmlTypeCode.HexBinary, + XmlTypeCode.Base64Binary, + XmlTypeCode.AnyUri, + XmlTypeCode.QName, + XmlTypeCode.Notation, + XmlTypeCode.NormalizedString, + XmlTypeCode.Token, + XmlTypeCode.Language, + XmlTypeCode.Idref, // IDREFS (LAMESPEC) + XmlTypeCode.Entity, // ENTITIES (LAMESPEC) + XmlTypeCode.NmToken, + XmlTypeCode.NmToken, // NMTOKENS (LAMESPEC) + XmlTypeCode.Name, + XmlTypeCode.NCName, + XmlTypeCode.Id, + XmlTypeCode.Idref, + XmlTypeCode.Entity, + XmlTypeCode.Integer, + XmlTypeCode.NonPositiveInteger, + XmlTypeCode.NegativeInteger, + XmlTypeCode.Long, + XmlTypeCode.Int, + XmlTypeCode.Short, + XmlTypeCode.Byte, + XmlTypeCode.NonNegativeInteger, + XmlTypeCode.UnsignedLong, + XmlTypeCode.UnsignedInt, + XmlTypeCode.UnsignedShort, + XmlTypeCode.UnsignedByte, + XmlTypeCode.PositiveInteger}; + + [Test] + public void TypeCode () + { + for (int i = 0; i < all_types.Length; i++) { + string name = all_types [i]; + QName qname = new QName (name, XmlSchema.Namespace); + Assert.AreEqual (type_codes [i], + XmlSchemaType.GetBuiltInSimpleType (qname).TypeCode, name); + } + } + +#endif + } +} diff --git a/mcs/class/System.XML/Test/System.Xml/ChangeLog b/mcs/class/System.XML/Test/System.Xml/ChangeLog index 441ca9c9bfa..2e69a65947e 100644 --- a/mcs/class/System.XML/Test/System.Xml/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml/ChangeLog @@ -1,3 +1,17 @@ +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlTextWriterTests.cs : Split AutoCreatePrefixes() and marked as + Ignore rather than NotWorking. Also it is not for bug #77086 and + #77077 (they were fixed). See bug #77088. + +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlTextWriterTests.cs : re-enabled WriteNmToken_InvalidChars(). + +2006-01-12 Atsushi Enomoto <atsushi@ximian.com> + + * XmlTextWriterTests.cs : re-enabled bug #77094 related tests. + 2006-01-06 Atsushi Enomoto <atsushi@ximian.com> * XmlWriterTests.cs : added tests for WriteNode(XPathNavigator, bool) diff --git a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs index 90661afd68c..b70e2cce2a1 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs @@ -205,29 +205,26 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] // bug #77086, #77087 and #77088 + [Ignore ("Due to the (silly) dependency on bug #77088, this test will not be fixed. The test could be rewritten but it depends on the original test author.")] public void AutoCreatePrefixes () { + xtw.WriteStartElement ("root"); xtw.WriteAttributeString (null, "abc", "http://somenamespace.com", "http://abc.def"); xtw.WriteAttributeString (null, "def", "http://somenamespace.com", "http://def.ghi"); xtw.WriteAttributeString (null, "ghi", "http://othernamespace.com", "http://ghi.jkl"); + xtw.WriteEndElement (); -#if NET_2_0 - Assert.AreEqual ("d0p1:abc='http://abc.def' d0p1:def='http://def.ghi'" + - " d0p2:ghi='http://ghi.jkl'", StringWriterText, "#1"); -#else - // on 1.x a new prefix is always created when level is 0 ? - Assert.AreEqual ("d0p1:abc='http://abc.def' d0p2:def='http://def.ghi'" + - " d0p3:ghi='http://ghi.jkl'", StringWriterText, "#1"); -#endif - - sw.GetStringBuilder ().Length = 0; - CreateXmlTextWriter (); + Assert.AreEqual ("<root d1p1:abc='http://abc.def' d1p1:def='http://def.ghi' d1p2:ghi='http://ghi.jkl' xmlns:d1p2='http://othernamespace.com' xmlns:d1p1='http://somenamespace.com' />", StringWriterText, "#1"); + } + [Test] + [Ignore ("Due to the (silly) dependency on bug #77088, this test will not be fixed. The test could be rewritten but it depends on the original test author.")] + public void AutoCreatePrefixes2 () + { xtw.WriteStartElement ("person"); - xtw.WriteAttributeString (null, "name", "http://somenamespace.com", "Gates"); - xtw.WriteAttributeString (null, "initials", "http://othernamespace.com", "BG"); - xtw.WriteAttributeString (null, "firstName", "http://somenamespace.com", "Bill"); + xtw.WriteAttributeString (null, "name", "http://somenamespace.com", "Driesen"); + xtw.WriteAttributeString (null, "initials", "http://othernamespace.com", "GD"); + xtw.WriteAttributeString (null, "firstName", "http://somenamespace.com", "Gert"); xtw.WriteStartElement ("address"); xtw.WriteAttributeString (null, "street", "http://somenamespace.com", "Campus"); xtw.WriteAttributeString (null, "number", "http://othernamespace.com", "1"); @@ -238,9 +235,9 @@ namespace MonoTests.System.Xml Assert.AreEqual ( "<person" + - " d1p1:name='Gates'" + - " d1p2:initials='BG'" + - " d1p1:firstName='Bill'" + + " d1p1:name='Driesen'" + + " d1p2:initials='GD'" + + " d1p1:firstName='Gert'" + " xmlns:d1p2='http://othernamespace.com'" + " xmlns:d1p1='http://somenamespace.com'>" + "<address" + @@ -525,12 +522,8 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] public void WriteStartElement_XmlPrefix () { - // uncomment the next code block once bug #77094 has been fixed. - - /* xtw.WriteStartElement ("xml", "something", "http://www.w3.org/XML/1998/namespace"); Assert.AreEqual ("<xml:something", StringWriterText, "#1"); @@ -548,7 +541,6 @@ namespace MonoTests.System.Xml sw.GetStringBuilder ().Length = 0; CreateXmlTextWriter (); - */ } [Test] @@ -559,7 +551,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] // bug #77094 [ExpectedException (typeof (ArgumentException))] public void WriteStartElement_XmlPrefix_Invalid2 () { @@ -1536,7 +1527,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] // on mono, an XmlException is thrown instead [ExpectedException (typeof (ArgumentException))] public void WriteNmToken_InvalidChars () { diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog b/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog index 3fa61cb1cd3..a645e2bff91 100644 --- a/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog @@ -1,3 +1,7 @@ +2006-01-11 Atsushi Enomoto <atsushi@ximian.com> + + * datatypesTest.xsd : missing required file for xsd tests. + 2005-12-26 Atsushi Enomoto <atsushi@ximian.com> * multi-schemaLocation.xml, diff --git a/mcs/class/System.XML/Test/XmlFiles/xsd/datatypesTest.xsd b/mcs/class/System.XML/Test/XmlFiles/xsd/datatypesTest.xsd new file mode 100644 index 00000000000..50fb15c3740 --- /dev/null +++ b/mcs/class/System.XML/Test/XmlFiles/xsd/datatypesTest.xsd @@ -0,0 +1,11 @@ +<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" + xmlns="urn:bar" targetNamespace="urn:bar"> + <xs:element name="e00"> + <xs:complexType> + </xs:complexType> + </xs:element> + <xs:element name="e4" type="xs:string" /> + <xs:element name="e1" type="xs:normalizedString" /> + <xs:element name="e2" type="xs:token" /> + <xs:element name="e3" type="xs:language" /> +</xs:schema> |