|
|
@@ -1,7 +1,5 @@
|
|
|
// Author: Dwivedi, Ajay kumar
|
|
|
// [email protected]
|
|
|
-// Author: Dwivedi, Ajay kumar
|
|
|
-// [email protected]
|
|
|
using System;
|
|
|
using System.Xml;
|
|
|
using System.IO;
|
|
|
@@ -13,11 +11,13 @@ namespace System.Xml.Schema
|
|
|
/// <summary>
|
|
|
/// Summary description for XmlSchema.
|
|
|
/// </summary>
|
|
|
- [XmlRoot]
|
|
|
+ [XmlRoot("schema",Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
public class XmlSchema : XmlSchemaObject
|
|
|
{
|
|
|
//public constants
|
|
|
+ [XmlIgnore]
|
|
|
public const string InstanceNamespace = "http://www.w3.org/2001/XMLSchema-instance";
|
|
|
+ [XmlIgnore]
|
|
|
public const string Namespace = "http://www.w3.org/2001/XMLSchema";
|
|
|
|
|
|
//private fields
|
|
|
@@ -37,8 +37,8 @@ namespace System.Xml.Schema
|
|
|
private XmlSchemaObjectTable schemaTypes ;
|
|
|
private string targetNamespace ;
|
|
|
private XmlAttribute[] unhandledAttributes ;
|
|
|
- private string version ;
|
|
|
-
|
|
|
+ private string version;
|
|
|
+ private string language;
|
|
|
|
|
|
public XmlSchema()
|
|
|
{
|
|
|
@@ -50,108 +50,150 @@ namespace System.Xml.Schema
|
|
|
isCompiled = false;
|
|
|
items = new XmlSchemaObjectCollection();
|
|
|
}
|
|
|
+
|
|
|
+ #region Properties
|
|
|
+
|
|
|
[DefaultValue(XmlSchemaForm.None)]
|
|
|
- [XmlAttribute]
|
|
|
+ [System.Xml.Serialization.XmlAttribute("attributeFormDefault")]
|
|
|
public XmlSchemaForm AttributeFormDefault
|
|
|
{
|
|
|
get{ return attributeFormDefault; }
|
|
|
set{ this.attributeFormDefault = value;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable AttributeGroups
|
|
|
{
|
|
|
get{ return attributeGroups; }
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable Attributes
|
|
|
{
|
|
|
get{ return attributes;}
|
|
|
}
|
|
|
+
|
|
|
[DefaultValue(XmlSchemaDerivationMethod.None)]
|
|
|
- [XmlAttribute]
|
|
|
+ [System.Xml.Serialization.XmlAttribute("blockDefault")]
|
|
|
public XmlSchemaDerivationMethod BlockDefault
|
|
|
{
|
|
|
get{ return blockDefault;}
|
|
|
set{ blockDefault = value;}
|
|
|
}
|
|
|
+
|
|
|
[DefaultValue(XmlSchemaForm.None)]
|
|
|
- [XmlAttribute]
|
|
|
+ [System.Xml.Serialization.XmlAttribute("elementFormDefault")]
|
|
|
public XmlSchemaForm ElementFormDefault
|
|
|
{
|
|
|
get{ return elementFormDefault;}
|
|
|
set{ elementFormDefault = value;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable Elements
|
|
|
{
|
|
|
get{ return elements;}
|
|
|
}
|
|
|
+
|
|
|
[DefaultValue(XmlSchemaDerivationMethod.None)]
|
|
|
- [XmlAttribute]
|
|
|
+ [System.Xml.Serialization.XmlAttribute("finalDefault")]
|
|
|
public XmlSchemaDerivationMethod FinalDefault
|
|
|
{
|
|
|
get{ return finalDefault;}
|
|
|
set{ finalDefault = value;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable Groups
|
|
|
{
|
|
|
get{ return groups;}
|
|
|
}
|
|
|
- [XmlAttribute]
|
|
|
+
|
|
|
+ [System.Xml.Serialization.XmlAttribute("id")]
|
|
|
public string Id
|
|
|
{
|
|
|
get{ return id;}
|
|
|
set{ id = value;}
|
|
|
}
|
|
|
- [XmlElement]
|
|
|
+
|
|
|
+ [XmlElement("include",typeof(XmlSchemaInclude),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("import",typeof(XmlSchemaImport),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("redefine",typeof(XmlSchemaRedefine),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
public XmlSchemaObjectCollection Includes
|
|
|
{
|
|
|
get{ return includes;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public bool IsCompiled
|
|
|
{
|
|
|
get{ return isCompiled;}
|
|
|
}
|
|
|
- [XmlElement]
|
|
|
+
|
|
|
+ [XmlElement("simpleType",typeof(XmlSchemaSimpleType),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("complexType",typeof(XmlSchemaComplexType),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("group",typeof(XmlSchemaGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ //Only Schema's attributeGroup has type XmlSchemaAttributeGroup.
|
|
|
+ //Others (complextype, restrictions etc) must have XmlSchemaAttributeGroupRef
|
|
|
+ [XmlElement("attributeGroup",typeof(XmlSchemaAttributeGroup),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("element",typeof(XmlSchemaElement),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("attribute",typeof(XmlSchemaAttribute),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("notation",typeof(XmlSchemaNotation),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
+ [XmlElement("annotation",typeof(XmlSchemaAnnotation),Namespace="http://www.w3.org/2001/XMLSchema")]
|
|
|
public XmlSchemaObjectCollection Items
|
|
|
{
|
|
|
get{ return items;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable Notations
|
|
|
{
|
|
|
get{ return notations;}
|
|
|
}
|
|
|
+
|
|
|
[XmlIgnore]
|
|
|
public XmlSchemaObjectTable SchemaTypes
|
|
|
{
|
|
|
get{ return schemaTypes;}
|
|
|
}
|
|
|
- [XmlAttribute]
|
|
|
+
|
|
|
+ [System.Xml.Serialization.XmlAttribute("targetNamespace")]
|
|
|
public string TargetNamespace
|
|
|
{
|
|
|
get{ return targetNamespace;}
|
|
|
set{ targetNamespace = value;}
|
|
|
}
|
|
|
+
|
|
|
[XmlAnyAttribute]
|
|
|
public XmlAttribute[] UnhandledAttributes
|
|
|
{
|
|
|
get{ return unhandledAttributes;}
|
|
|
set{ unhandledAttributes = value;}
|
|
|
}
|
|
|
- [XmlAttribute]
|
|
|
+
|
|
|
+ [System.Xml.Serialization.XmlAttribute("version")]
|
|
|
public string Version
|
|
|
{
|
|
|
get{ return version;}
|
|
|
set{ version = value;}
|
|
|
}
|
|
|
|
|
|
+ // New attribute defined in W3C schema element
|
|
|
+ [System.Xml.Serialization.XmlAttribute("xml:lang")]
|
|
|
+ public string Language
|
|
|
+ {
|
|
|
+ get{ return language; }
|
|
|
+ set{ language = value; }
|
|
|
+ }
|
|
|
+
|
|
|
+ #endregion
|
|
|
+
|
|
|
// Methods
|
|
|
[MonoTODO]
|
|
|
- public void Compile(System.Xml.Schema.ValidationEventHandler validationEventHandler)
|
|
|
+ public void Compile(ValidationEventHandler validationEventHandler)
|
|
|
{
|
|
|
+ attributeGroups = null;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
public static XmlSchema Read(TextReader reader, ValidationEventHandler validationEventHandler)
|
|
|
@@ -162,19 +204,54 @@ namespace System.Xml.Schema
|
|
|
{
|
|
|
return Read(new XmlTextReader(stream),validationEventHandler);
|
|
|
}
|
|
|
+ //<ToBeRemoved>
|
|
|
+ private static void Serializer_UnknownAttribute(object sender, XmlAttributeEventArgs e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Unknown Attribute");
|
|
|
+ Console.WriteLine("\t" + e.Attr.Name + " " + e.Attr.InnerXml);
|
|
|
+ Console.WriteLine("\t LineNumber: " + e.LineNumber);
|
|
|
+ Console.WriteLine("\t LinePosition: " + e.LinePosition);
|
|
|
+ }
|
|
|
+ private static void Serializer_UnknownElement(object sender, XmlElementEventArgs e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Unknown Element");
|
|
|
+ Console.WriteLine("\t" + e.Element.Name + " " + e.Element.InnerXml);
|
|
|
+ Console.WriteLine("\t LineNumber: " + e.LineNumber);
|
|
|
+ Console.WriteLine("\t LinePosition: " + e.LinePosition);
|
|
|
+ }
|
|
|
+ private static void Serializer_UnknownNode(object sender, XmlNodeEventArgs e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Unknown Node");
|
|
|
+ Console.WriteLine("\t" + e.Name + " " + e.Text);
|
|
|
+ Console.WriteLine("\t LineNumber: " + e.LineNumber);
|
|
|
+ Console.WriteLine("\t LinePosition: " + e.LinePosition);
|
|
|
+ }
|
|
|
+ private static void Serializer_UnknownAttribute(object sender, UnreferencedObjectEventArgs e)
|
|
|
+ {
|
|
|
+ Console.WriteLine("Unknown");
|
|
|
+ Console.WriteLine("\t" + e.UnreferencedId);
|
|
|
+ Console.WriteLine("\t" + e.UnreferencedObject);
|
|
|
+ }
|
|
|
+ //</ToBeRemoved>
|
|
|
[MonoTODO]
|
|
|
public static XmlSchema Read(XmlReader reader, ValidationEventHandler validationEventHandler)
|
|
|
{
|
|
|
- return null;
|
|
|
+ XmlSerializer xser = new XmlSerializer(typeof(XmlSchema));
|
|
|
+ //<ToBeRemoved>
|
|
|
+ xser.UnknownAttribute += new XmlAttributeEventHandler(Serializer_UnknownAttribute);
|
|
|
+ xser.UnknownElement += new XmlElementEventHandler(Serializer_UnknownElement);
|
|
|
+ xser.UnknownNode += new XmlNodeEventHandler(Serializer_UnknownNode);
|
|
|
+ xser.UnreferencedObject += new UnreferencedObjectEventHandler(Serializer_UnknownAttribute);
|
|
|
+ //</ToBeRemoved>
|
|
|
+ return (XmlSchema) xser.Deserialize(reader);
|
|
|
}
|
|
|
-
|
|
|
public void Write(System.IO.Stream stream)
|
|
|
{
|
|
|
- Write(new XmlTextWriter(stream,null),null);
|
|
|
+ Write(stream,null);
|
|
|
}
|
|
|
public void Write(System.IO.TextWriter writer)
|
|
|
{
|
|
|
- Write(new XmlTextWriter(writer),null);
|
|
|
+ Write(writer,null);
|
|
|
}
|
|
|
public void Write(System.Xml.XmlWriter writer)
|
|
|
{
|
|
|
@@ -186,11 +263,41 @@ namespace System.Xml.Schema
|
|
|
}
|
|
|
public void Write(System.IO.TextWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
|
|
|
{
|
|
|
- Write(new XmlTextWriter(writer),namespaceManager);
|
|
|
+ XmlTextWriter xwriter = new XmlTextWriter(writer);
|
|
|
+ // This is why the Write was not writing schema with line breaks
|
|
|
+ xwriter.Formatting = Formatting.Indented;
|
|
|
+ Write(xwriter,namespaceManager);
|
|
|
}
|
|
|
[MonoTODO]
|
|
|
public void Write(System.Xml.XmlWriter writer, System.Xml.XmlNamespaceManager namespaceManager)
|
|
|
{
|
|
|
+ XmlSerializerNamespaces xns;
|
|
|
+
|
|
|
+ if(Namespaces != null)
|
|
|
+ {
|
|
|
+ xns = new XmlSerializerNamespaces(this.Namespaces);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ xns = new XmlSerializerNamespaces();
|
|
|
+ }
|
|
|
+
|
|
|
+ if(namespaceManager != null)
|
|
|
+ {
|
|
|
+ foreach(string name in namespaceManager)
|
|
|
+ {
|
|
|
+ //xml and xmlns namespaced are added by default in namespaceManager.
|
|
|
+ //So we should ignore them
|
|
|
+ if(name!="xml" && name != "xmlns")
|
|
|
+ xns.Add(name,namespaceManager.LookupNamespace(name));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ this.Namespaces = xns;
|
|
|
+
|
|
|
+ XmlSerializer xser = new XmlSerializer(typeof(XmlSchema));
|
|
|
+ xser.Serialize(writer,this,xns);
|
|
|
+ writer.Flush();
|
|
|
}
|
|
|
}
|
|
|
}
|