private void WriteUniques(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            foreach (var item in dataTable.Columns)
            {
                if (item.Unique == false)
                {
                    continue;
                }

                if (item.IsKey == true && dataTable.PrimaryKey.Length == 1)
                {
                    continue;
                }

                var unique = new XmlSchemaUnique()
                {
                    Name     = dataTable.Name + "." + item.ColumnName + "." + "Unique",
                    Selector = new XmlSchemaXPath()
                };
                unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                unique.Fields.Add(field);
                element.Constraints.Add(unique);
            }
        }
Beispiel #2
0
        private void WriteKeys(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            if (dataTable.PrimaryKey.Any() == false)
            {
                return;
            }

            var key = new XmlSchemaKey()
            {
                Name     = dataTable.KeyTypeName,
                Selector = new XmlSchemaXPath()
            };

            key.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

            foreach (var item in dataTable.PrimaryKey)
            {
                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                key.Fields.Add(field);
            }

            element.Constraints.Add(key);
        }
Beispiel #3
0
        public XmlScopeKeyPartData RegisterField(XmlSchemaXPath partInfo)
        {
            var partData = new XmlScopeKeyPartData(this, _parts.Count, partInfo);

            _parts.Add(partData);
            return(partData);
        }
Beispiel #4
0
        private void WriteUniques(XmlSchema schema, XmlSchemaElement element, CremaDataTable dataTable)
        {
            //var query = from item in dataTable.Columns
            //            where item.Unique == true
            //            select item;

            //if (query.Any() == false)
            //    return;

            //var unique = new XmlSchemaUnique()
            //{
            //    Name = dataTable.UniqueTypeName,
            //    Selector = new XmlSchemaXPath()
            //};
            //unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

            //foreach (var item in query)
            //{
            //    var field = new XmlSchemaXPath()
            //    {
            //        XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
            //    };
            //    unique.Fields.Add(field);
            //}
            //element.Constraints.Add(unique);

            foreach (var item in dataTable.Columns)
            {
                if (item.Unique == false)
                {
                    continue;
                }

                if (item.IsKey == true && dataTable.PrimaryKey.Length == 1)
                {
                    continue;
                }

                var unique = new XmlSchemaUnique()
                {
                    Name     = dataTable.Name + "." + item.ColumnName + "." + "Unique",
                    Selector = new XmlSchemaXPath()
                };
                unique.Selector.XPath = dataTable.GetSelectorXPath(CremaSchema.TableTypePrefix, schema.TargetNamespace);

                var field = new XmlSchemaXPath()
                {
                    XPath = CremaSchema.TableTypePrefix + ":" + item.ColumnName
                };
                unique.Fields.Add(field);
                element.Constraints.Add(unique);
            }
        }
Beispiel #5
0
 private void Write49_XmlSchemaXPath(string name, string ns, XmlSchemaXPath o)
 {
     if (o != null)
     {
         this.WriteStartElement(name);
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttribute("xpath", "", o.XPath);
         this.WriteAttributes(o.UnhandledAttributes, o);
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteEndElement();
     }
 }
 void Write49_XmlSchemaXPath(string name, string ns, XmlSchemaXPath o)
 {
     if ((object)o == null)
     {
         return;
     }
     WriteStartElement(name);
     WriteAttribute(@"id", @"", o.@Id);
     WriteAttribute(@"xpath", @"", o.@XPath);
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     WriteEndElement();
 }
Beispiel #7
0
 public XsdIdentityField(XmlSchemaXPath field, int index)
 {
     this.index = index;
     fieldPaths = field.CompiledExpression;
 }
Beispiel #8
0
 public XsdIdentitySelector(XmlSchemaXPath selector)
 {
     selectorPaths = selector.CompiledExpression;
 }
Beispiel #9
0
    public static void Main()
    {
        XmlTextReader tr     = new XmlTextReader("empty.xsd");
        XmlSchema     schema = XmlSchema.Read(tr, new ValidationEventHandler(ValidationCallback));

        schema.ElementFormDefault = XmlSchemaForm.Qualified;

        schema.TargetNamespace = "http://www.example.com/Report";

        {
            XmlSchemaElement element = new XmlSchemaElement();
            element.Name = "purchaseReport";

            XmlSchemaComplexType element_complexType = new XmlSchemaComplexType();

            XmlSchemaSequence element_complexType_sequence = new XmlSchemaSequence();

            {
                XmlSchemaElement element_complexType_sequence_element = new XmlSchemaElement();
                element_complexType_sequence_element.Name           = "region";
                element_complexType_sequence_element.SchemaTypeName =
                    new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
                ;

                {
                    XmlSchemaKeyref element_complexType_sequence_element_keyref = new XmlSchemaKeyref();
                    element_complexType_sequence_element_keyref.Name           = "dummy2";
                    element_complexType_sequence_element_keyref.Selector       = new XmlSchemaXPath();
                    element_complexType_sequence_element_keyref.Selector.XPath = "r:zip/r:part";

                    {
                        XmlSchemaXPath field = new XmlSchemaXPath();

                        field.XPath = "@number";
                        element_complexType_sequence_element_keyref.Fields.Add(field);
                    }
                    element_complexType_sequence_element_keyref.Refer =
                        new XmlQualifiedName("pNumKey", "http://www.example.com/Report")
                    ;
                    element_complexType_sequence_element.Constraints.Add(element_complexType_sequence_element_keyref);
                }
                element_complexType_sequence.Items.Add(element_complexType_sequence_element);
            }
            element_complexType.Particle = element_complexType_sequence;

            {
                XmlSchemaAttribute element_complexType_attribute = new XmlSchemaAttribute();
                element_complexType_attribute.Name           = "periodEnding";
                element_complexType_attribute.SchemaTypeName =
                    new XmlQualifiedName("date", "http://www.w3.org/2001/XMLSchema")
                ;
                element_complexType.Attributes.Add(element_complexType_attribute);
            }
            element.SchemaType = element_complexType;

            {
                XmlSchemaKey element_key = new XmlSchemaKey();
                element_key.Name           = "pNumKey";
                element_key.Selector       = new XmlSchemaXPath();
                element_key.Selector.XPath = "r:parts/r:part";

                {
                    XmlSchemaXPath field = new XmlSchemaXPath();

                    field.XPath = "@number";
                    element_key.Fields.Add(field);
                }
                element.Constraints.Add(element_key);
            }

            schema.Items.Add(element);
        }

        schema.Write(Console.Out);
    }/* Main() */
Beispiel #10
0
        public XmlSchemaComplexType FindBaseType(XmlSchemaObject baseObject)
        {
            if (baseObject is XmlSchemaComplexContentExtension)
            {
                XmlSchemaComplexContentExtension baseComplexContentExtension = baseObject as XmlSchemaComplexContentExtension;
                return(FindComplexType(baseComplexContentExtension));
            }

            if (baseObject is XmlSchemaComplexType)
            {
                XmlSchemaComplexType baseComplexType = baseObject as XmlSchemaComplexType;
                if (baseComplexType.Parent is XmlSchemaElement)
                {
                    XmlSchemaElement baseElement = baseComplexType.Parent as XmlSchemaElement;

                    XmlSchemaIdentityConstraint primaryKey = FindPrimaryKey(baseElement);
                    if (primaryKey == null)
                    {
                        return(null);
                    }

                    foreach (XmlSchemaObject xmlSchemaObject in RootSchema.Items)
                    {
                        if (xmlSchemaObject is XmlSchemaElement)
                        {
                            if (IsDataSetElement(xmlSchemaObject))
                            {
                                XmlSchemaElement dataSetElement = xmlSchemaObject as XmlSchemaElement;

                                foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in dataSetElement.Constraints)
                                {
                                    if (xmlSchemaIdentityConstraint is XmlSchemaKeyref)
                                    {
                                        XmlSchemaKeyref xmlSchemaKeyref = xmlSchemaIdentityConstraint as XmlSchemaKeyref;
                                        if (this.FindSelector(xmlSchemaKeyref) == baseElement)
                                        {
                                            bool isMatch = xmlSchemaKeyref.Fields.Count == primaryKey.Fields.Count;
                                            for (int index = 0; index < xmlSchemaKeyref.Fields.Count; index++)
                                            {
                                                XmlSchemaXPath xPath1 = (XmlSchemaXPath)xmlSchemaKeyref.Fields[index];
                                                XmlSchemaXPath xPath2 = (XmlSchemaXPath)primaryKey.Fields[index];
                                                if (xPath1.XPath != xPath2.XPath)
                                                {
                                                    isMatch = false;
                                                    break;
                                                }
                                            }

                                            if (isMatch)
                                            {
                                                XmlSchemaIdentityConstraint xmlSchemaKey     = FindKey(xmlSchemaKeyref);
                                                XmlSchemaElement            xmlSchemaElement = FindSelector(xmlSchemaKey);
                                                return(xmlSchemaElement.SchemaType as XmlSchemaComplexType);
                                            }
                                        }
                                    }
                                }
                            }
                            else
                            {
                                XmlSchemaElement tableElement = xmlSchemaObject as XmlSchemaElement;

                                foreach (XmlSchemaIdentityConstraint xmlSchemaIdentityConstraint in tableElement.Constraints)
                                {
                                }
                            }
                        }
                    }

                    return(null);
                }
            }

            return(null);
        }
Beispiel #11
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <xs:complexType name="customerOrderType">
        XmlSchemaComplexType customerOrderType = new XmlSchemaComplexType();

        customerOrderType.Name = "customerOrderType";

        // <xs:sequence>
        XmlSchemaSequence sequence1 = new XmlSchemaSequence();

        // <xs:element name="item" minOccurs="0" maxOccurs="unbounded">
        XmlSchemaElement item = new XmlSchemaElement();

        item.MinOccurs       = 0;
        item.MaxOccursString = "unbounded";
        item.Name            = "item";

        // <xs:complexType>
        XmlSchemaComplexType ct1 = new XmlSchemaComplexType();

        // <xs:attribute name="itemID" type="xs:string"/>
        XmlSchemaAttribute itemID = new XmlSchemaAttribute();

        itemID.Name           = "itemID";
        itemID.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // </xs:complexType>
        ct1.Attributes.Add(itemID);

        // </xs:element>
        item.SchemaType = ct1;

        // </xs:sequence>
        sequence1.Items.Add(item);
        customerOrderType.Particle = sequence1;

        // <xs:attribute name="CustomerID" type="xs:string"/>
        XmlSchemaAttribute CustomerID = new XmlSchemaAttribute();

        CustomerID.Name           = "CustomerID";
        CustomerID.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        customerOrderType.Attributes.Add(CustomerID);

        // </xs:complexType>
        schema.Items.Add(customerOrderType);

        // <xs:element name="ordersByCustomer">
        XmlSchemaElement ordersByCustomer = new XmlSchemaElement();

        ordersByCustomer.Name = "ordersByCustomer";

        // <xs:complexType>
        XmlSchemaComplexType ct2 = new XmlSchemaComplexType();

        // <xs:sequence>
        XmlSchemaSequence sequence2 = new XmlSchemaSequence();

        // <xs:element name="customerOrders" type="customerOrderType" minOccurs="0" maxOccurs="unbounded" />
        XmlSchemaElement customerOrders = new XmlSchemaElement();

        customerOrders.MinOccurs       = 0;
        customerOrders.MaxOccursString = "unbounded";
        customerOrders.Name            = "customerOrders";
        customerOrders.SchemaTypeName  = new XmlQualifiedName("customerOrderType", "");

        // </xs:sequence>
        sequence2.Items.Add(customerOrders);

        // </xs:complexType>
        ct2.Particle = sequence2;
        ordersByCustomer.SchemaType = ct2;

        // <xs:unique name="oneCustomerOrdersforEachCustomerID">
        XmlSchemaUnique element_unique = new XmlSchemaUnique();

        element_unique.Name = "oneCustomerOrdersforEachCustomerID";

        // <xs:selector xpath="customerOrders"/>
        element_unique.Selector       = new XmlSchemaXPath();
        element_unique.Selector.XPath = "customerOrders";

        // <xs:field xpath="@customerID"/>
        XmlSchemaXPath field = new XmlSchemaXPath();

        field.XPath = "@customerID";

        // </xs:unique>
        element_unique.Fields.Add(field);
        ordersByCustomer.Constraints.Add(element_unique);

        // </xs:element>
        schema.Items.Add(ordersByCustomer);

        XmlSchemaSet schemaSet = new XmlSchemaSet();

        schemaSet.ValidationEventHandler += new ValidationEventHandler(ValidationCallbackOne);
        schemaSet.Add(schema);
        schemaSet.Compile();

        XmlSchema compiledSchema = null;

        foreach (XmlSchema schema1 in schemaSet.Schemas())
        {
            compiledSchema = schema1;
        }

        XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

        nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");
        compiledSchema.Write(Console.Out, nsmgr);
    }
Beispiel #12
0
 private static void Equal(XmlSchemaXPath expected, XmlSchemaXPath actual)
 {
     throw new NotImplementedException();
 }
Beispiel #13
0
 public XmlScopeKeyPartData(XmlScopeKeyData keyData, int index, XmlSchemaXPath partInfo)
 {
     this.KeyData  = keyData;
     this.Index    = index;
     this.PartInfo = partInfo;
 }
 protected virtual void Visit(XmlSchemaXPath xPath)
 {
 }
Beispiel #15
0
 public FieldSchema(XmlSchemaXPath xmlSchemaXPath)
 {
 }