get { return !EOF && attr < 0 && node is XElement ? ((XElement) node).IsEmpty : false; }
}
- XAttribute GetCurrentAttribute ()
+ internal XAttribute GetCurrentAttribute ()
{
return GetXAttribute (attr);
}
{
throw new NotSupportedException ();
}
+
+ // Note that this does not return attribute node.
+ internal XNode CurrentNode {
+ get { return node; }
+ }
}
}
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Xml;
namespace System.Xml.Linq
public object Annotation (Type type)
{
- if (annotations != null)
- foreach (object o in annotations)
- if (o.GetType () == type)
- return o;
- return null;
+ return Annotations (type).FirstOrDefault ();
}
public IEnumerable<T> Annotations<T> () where T : class
public IEnumerable<object> Annotations (Type type)
{
+ if (type == null)
+ throw new ArgumentNullException ("type");
if (annotations == null)
yield break;
foreach (object o in annotations)
- if (o.GetType () == type)
+ if (type.IsAssignableFrom (o.GetType ()))
yield return o;
}
if (annotations == null)
return;
for (int i = 0; i < annotations.Count; i++)
- if (annotations [i].GetType () == type)
+ if (type.IsAssignableFrom (annotations [i].GetType ()))
annotations.RemoveAt (i);
}
namespace System.Xml.Schema
{
- [MonoTODO]
public static class Extensions
{
- [MonoTODO]
public static IXmlSchemaInfo GetSchemaInfo (this XAttribute attribute)
{
- throw new NotImplementedException ();
+ return attribute.Annotation<IXmlSchemaInfo> ();
}
- [MonoTODO]
public static IXmlSchemaInfo GetSchemaInfo (this XElement element)
{
- throw new NotImplementedException ();
+ return element.Annotation<IXmlSchemaInfo> ();
}
[MonoTODO]
throw new NotImplementedException ();
}
- [MonoTODO]
public static void Validate (this XDocument document, XmlSchemaSet schemas, ValidationEventHandler handler)
{
- throw new NotImplementedException ();
+ Validate (document, schemas, handler, false);
}
- [MonoTODO]
public static void Validate (this XDocument document, XmlSchemaSet schemas, ValidationEventHandler handler, bool addSchemaInfo)
{
- throw new NotImplementedException ();
+ if (document == null)
+ throw new ArgumentNullException ("document");
+ if (schemas == null)
+ throw new ArgumentNullException ("schemas");
+ var xrs = new XmlReaderSettings () { ValidationType = ValidationType.Schema };
+ xrs.Schemas = schemas;
+ xrs.ValidationEventHandler += handler;
+ var source = new XNodeReader (document);
+ var xr = XmlReader.Create (source, xrs);
+ while (xr.Read ()) {
+ if (addSchemaInfo) {
+ if (xr.NodeType == XmlNodeType.Element) {
+ source.CurrentNode.AddAnnotation (xr.SchemaInfo);
+ while (xr.MoveToNextAttribute ())
+ if (xr.NamespaceURI != XUtil.XmlnsNamespace)
+ source.GetCurrentAttribute ().AddAnnotation (xr.SchemaInfo);
+ xr.MoveToElement ();
+ }
+ }
+ }
}
[MonoTODO]
// test succesfull validation
[Test]
- [Category ("NotWorking")]
public void XDocumentSuccessValidate ()
{
validationSucceded = true;
// test failed validation
[Test]
- [Category ("NotWorking")]
public void XDocumentFailValidate ()
{
String elementName = "AlteringElementName";
*/
[Test]
[ExpectedException (typeof (XmlSchemaValidationException))]
- [Category ("NotWorking")]
public void XDocumentThrowExceptionValidate ()
{
String elementName = "AlteringElementName";
* the post-schema-validation infoset (PSVI)
*/
[Test]
- [Category ("NotWorking")]
public void XDocumentAddSchemaInfoValidate ()
{
// no. of elements before validation
* the post-schema-validation infoset (PSVI).
*/
[Test]
- [Category ("NotWorking")]
public void XDocumentNoSchemaInfoValidate ()
{
// no. of elements before validation