Ejemplo n.º 1
0
        private void OnSetAttributeWildcard()
        {
            XmlSchemaAnyAttribute anyAttribute = _attributeWildcard?.SchemaObject as XmlSchemaAnyAttribute;

            if (_type.ContentModel is XmlSchemaComplexContent complexModel)
            {
                if (complexModel.Content is XmlSchemaComplexContentExtension contentExtension)
                {
                    contentExtension.AnyAttribute = anyAttribute;
                }

                else if (complexModel.Content is XmlSchemaComplexContentRestriction contentRestriction)
                {
                    contentRestriction.AnyAttribute = anyAttribute;
                }
            }
            else if (_type.ContentModel is XmlSchemaSimpleContent simpleModel)
            {
                if (simpleModel.Content is XmlSchemaSimpleContentExtension contentExtension)
                {
                    contentExtension.AnyAttribute = anyAttribute;
                }

                else if (simpleModel.Content is XmlSchemaSimpleContentRestriction contentRestriction)
                {
                    contentRestriction.AnyAttribute = anyAttribute;
                }
            }
        }
Ejemplo n.º 2
0
        private XmlSchemaAttribute FindSchemaInfo(XmlAttribute attributeToValidate)
        {
            XmlElement           parentElement     = attributeToValidate.OwnerElement;
            XmlSchemaObject      schemaObject      = FindSchemaInfo(parentElement);
            XmlSchemaComplexType elementSchemaType = GetComplexType(schemaObject);

            if (elementSchemaType == null)
            {
                return(null);
            }
            XmlQualifiedName   attName         = new XmlQualifiedName(attributeToValidate.LocalName, attributeToValidate.NamespaceURI);
            XmlSchemaAttribute schemaAttribute = elementSchemaType.AttributeUses[attName] as XmlSchemaAttribute;

            if (schemaAttribute == null)
            {
                XmlSchemaAnyAttribute anyAttribute = elementSchemaType.AttributeWildcard;
                if (anyAttribute != null)
                {
                    if (anyAttribute.NamespaceList.Allows(attName))
                    { //Match wildcard against global attribute
                        schemaAttribute = _schemas.GlobalAttributes[attName] as XmlSchemaAttribute;
                    }
                }
            }
            return(schemaAttribute);
        }
        /// <summary>Removes attributes from the specified <paramref name="element"/> if they're unexpected.</summary>
        /// <param name="element">Element to remove attributes from.</param>
        /// <param name="anyAttribute">anyAttribute schema for a complex type element (possibly null).</param>
        private void TrimAttributes(XElement element, XmlSchemaAnyAttribute anyAttribute)
        {
            Debug.Assert(element != null, "e != null");

            List <XAttribute> unexpectedAttributes = null;
            var expectedAttributes = validator.GetExpectedAttributes();

            foreach (XAttribute attribute in element.Attributes())
            {
                if (attribute.IsNamespaceDeclaration)
                {
                    continue;
                }

                if (!IsAttributeExpected(attribute, anyAttribute, expectedAttributes))
                {
                    AppendWithCreation(ref unexpectedAttributes, attribute);
                }
            }

            if (unexpectedAttributes != null)
            {
                foreach (var attribute in unexpectedAttributes)
                {
                    attribute.Remove();
                }
            }
        }
        static XmlSchemaType AddElementTypeToXmlSchema(IUxmlFactory factory, SchemaInfo schemaInfo, FactoryProcessingHelper processingData)
        {
            // We always have complex types with complex content.
            XmlSchemaComplexType elementType = new XmlSchemaComplexType();

            elementType.Name = factory.uxmlName + k_TypeSuffix;

            XmlSchemaComplexContent content = new XmlSchemaComplexContent();

            elementType.ContentModel = content;

            // We only support restrictions of base types.
            XmlSchemaComplexContentRestriction restriction = new XmlSchemaComplexContentRestriction();

            content.Content = restriction;

            if (factory.substituteForTypeName == String.Empty)
            {
                restriction.BaseTypeName = new XmlQualifiedName("anyType", k_XmlSchemaNamespace);
            }
            else
            {
                restriction.BaseTypeName = new XmlQualifiedName(factory.substituteForTypeName + k_TypeSuffix, factory.substituteForTypeNamespace);
                schemaInfo.importNamespaces.Add(factory.substituteForTypeNamespace);
            }

            if (factory.canHaveAnyAttribute)
            {
                XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax;
                restriction.AnyAttribute     = anyAttribute;
            }

            foreach (UxmlAttributeDescription attrDesc in factory.uxmlAttributesDescription)
            {
                XmlQualifiedName typeName = AddAttributeTypeToXmlSchema(schemaInfo, attrDesc, factory, processingData);
                if (typeName != null)
                {
                    AddAttributeToXmlSchema(restriction, attrDesc, typeName);
                    schemaInfo.importNamespaces.Add(attrDesc.typeNamespace);
                }
            }

            bool hasChildElements = false;

            foreach (UxmlChildElementDescription childDesc in factory.uxmlChildElementsDescription)
            {
                hasChildElements = true;
                schemaInfo.importNamespaces.Add(childDesc.elementNamespace);
            }

            if (hasChildElements)
            {
                restriction.Particle = MakeChoiceSequence(factory.uxmlChildElementsDescription);
            }

            schemaInfo.schema.Items.Add(elementType);
            return(elementType);
        }
        private void OnSetWildcard()
        {
            XmlSchemaAnyAttribute anyAttribute = _wildcard?.SchemaObject as XmlSchemaAnyAttribute;

            if (_attributeGroup is XmlSchemaAttributeGroup attributeGroup)
            {
                attributeGroup.AnyAttribute = anyAttribute;
            }
        }
Ejemplo n.º 6
0
 public SDataSchemaResourceType(string elementName)
     : base(elementName)
 {
     ListName         = elementName + "--list";
     ListItemName     = elementName;
     CanGet           = true;
     AnyAttribute     = new XmlSchemaAnyAttribute();
     ListAnyAttribute = new XmlSchemaAnyAttribute();
 }
        /*
         * const string SchemaString =
         * "<xsd:schema xmlns:xsd='" + XmlSchema.Namespace + "'>" +
         * "    <xsd:complexType name='XPathMessageFilter'>" +
         * "      <xsd:sequence>" +
         * "        <xsd:element name='" + InnerElem + "' >" +
         * "          <xsd:complexType>" +
         * "            <xsd:simpleContent>" +
         * "              <xsd:extension base='xsd:string'>" +
         * "                <xsd:attribute name='" + DialectAttr + "' type='xsd:string' use='optional'/>" +
         * "              </xsd:extension>" +
         * "            </xsd:simpleContent>" +
         * "          </xsd:complexType>" +
         * "        </xsd:element>" +
         * "      </xsd:sequence>" +
         * "      <xsd:attribute name='" + NodeQuotaAttr + "' type='xsd:int' use='optional'/>" +
         * "    </xsd:complexType>" +
         * "</xsd:schema>";
         *
         * static XPathMessageFilter()
         * {
         *  XPathMessageFilter.schema = XmlSchema.Read(new StringReader(SchemaString), null);
         * }
         */

        static XmlSchemaComplexType CreateOuterType()
        {
            // Dialect attribute
            XmlSchemaAttribute dAttr = new XmlSchemaAttribute();

            dAttr.Name           = DialectAttr;
            dAttr.SchemaTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
            dAttr.Use            = XmlSchemaUse.Optional;

            // Inner extension
            XmlSchemaSimpleContentExtension innerExt = new XmlSchemaSimpleContentExtension();

            innerExt.BaseTypeName = new XmlQualifiedName("string", XmlSchema.Namespace);
            innerExt.Attributes.Add(dAttr);

            // Inner content
            XmlSchemaSimpleContent innerContent = new XmlSchemaSimpleContent();

            innerContent.Content = innerExt;

            // Inner complexType
            XmlSchemaComplexType innerType = new XmlSchemaComplexType();

            innerType.ContentModel = innerContent;

            // Inner element
            XmlSchemaElement element = new XmlSchemaElement();

            element.Name       = InnerElem;
            element.SchemaType = innerType;

            // Seq around innner elem
            XmlSchemaSequence sequence = new XmlSchemaSequence();

            sequence.Items.Add(element);

            // NodeQuota attribute
            XmlSchemaAttribute nqAttr = new XmlSchemaAttribute();

            nqAttr.Name           = NodeQuotaAttr;
            nqAttr.SchemaTypeName = new XmlQualifiedName("int", XmlSchema.Namespace);
            nqAttr.Use            = XmlSchemaUse.Optional;

            // anyAttribute on outer type
            // any namespace is the default
            XmlSchemaAnyAttribute anyAttr = new XmlSchemaAnyAttribute();

            // Outer type
            XmlSchemaComplexType outerType = new XmlSchemaComplexType();

            outerType.Name     = OuterTypeName;
            outerType.Particle = sequence;
            outerType.Attributes.Add(nqAttr);
            outerType.AnyAttribute = anyAttr;

            return(outerType);
        }
Ejemplo n.º 8
0
        public IEnumerable <XmlSchemaObject> GetExtensionAttributes(XmlSchemaAnyAttribute parent)
        {
            List <XmlSchemaObject> attributes;

            if (!_extensionAttributes.TryGetValue(parent, out attributes))
            {
                return(_emptyObjectList);
            }

            return(attributes);
        }
        void Add_Attributes(TreeNode innerNode, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
        {
            foreach (XmlSchemaObject at in atts)
            {
                if (at is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr    = (XmlSchemaAttribute)at;
                    XmlSchemaAttribute refAttr = attr;

                    if (!attr.RefName.IsEmpty)
                    {
                        refAttr = GetRefAttribute(attr.RefName);
                        if (refAttr == null)
                        {
                            throw new Exception("Global attribute not found: " + attr.RefName);
                        }
                    }

                    string type;
                    if (!refAttr.SchemaTypeName.IsEmpty)
                    {
                        type = GetBuiltInTypeName(refAttr.SchemaTypeName);
                    }
                    else
                    {
                        type = GetBuiltInType(refAttr.SchemaType);
                    }

                    TreeNode node = new TreeNode(refAttr.Name);

                    if (refAttr.QualifiedName.Namespace != string.Empty)
                    {
                        node.Text = NamespaceHandler.LoopupPrefix(_namespaces, refAttr.QualifiedName.Namespace) + ":" + refAttr.Name;
                    }

                    NodeData data = new NodeData(at, refAttr.QualifiedName, type);
                    node.Tag = data;

                    innerNode.Nodes.Add(node);
                }
                else if (at is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
                    XmlSchemaAttributeGroup    grp  = (XmlSchemaAttributeGroup)_schemas.Find(gref.RefName, typeof(XmlSchemaAttributeGroup));
                    Add_Attributes(innerNode, grp.Attributes, grp.AnyAttribute);
                }
            }

            if (anyat != null)
            {
                TreeNode node = new TreeNode("any custom-attribute");
                innerNode.Nodes.Add(node);
            }
        }
        public void ReadFromFileWithoutNamespaceReturnsNull()
        {
            var                   xsd = @"<xs:schema xmlns:xs='http://www.w3.org/2001/XMLSchema' targetNamespace='ns'>
                        <xs:complexType name = 't'>
                            <xs:anyAttribute/>
                        </xs:complexType>
                        </xs:schema>";
            XmlSchema             xs  = XmlSchema.Read(new StringReader(xsd), null);
            XmlSchemaAnyAttribute any = ((XmlSchemaComplexType)xs.Items[0]).AnyAttribute;

            Assert.Null(any.Namespace);
        }
        public void v3(string ns, string attrNs, string expectedNs)
        {
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            xss.Add(GetSimpleSchema(ns, attrNs));
            xss.Compile();

            XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t", attrNs)]).AttributeWildcard;

            CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace);
        }
Ejemplo n.º 12
0
        static void AddAppSequenceType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            //<xs:complexType name="AppSequenceType" >
            XmlSchemaComplexType appSequenceType = new XmlSchemaComplexType();

            appSequenceType.Name = ProtocolStrings.SchemaNames.AppSequenceType;

            // <xs:complexContent>
            XmlSchemaComplexContent complexContent = new XmlSchemaComplexContent();

            appSequenceType.ContentModel = complexContent;

            // <xs:restriction base="xs:anyType" >
            XmlSchemaComplexContentRestriction contentRestriction = new XmlSchemaComplexContentRestriction();

            complexContent.Content          = contentRestriction;
            contentRestriction.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.AnyType;

            // <xs:attribute name="InstanceId" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute instanceId = new XmlSchemaAttribute();

            instanceId.Name           = ProtocolStrings.SchemaNames.AppSequenceInstanceId;
            instanceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            instanceId.Use            = XmlSchemaUse.Required;

            // <xs:attribute name="SequenceId" type="xs:anyURI" />
            XmlSchemaAttribute sequenceId = new XmlSchemaAttribute();

            sequenceId.Name           = ProtocolStrings.SchemaNames.AppSequenceSequenceId;
            sequenceId.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            // <xs:attribute name="MessageNumber" type="xs:unsignedInt" use="required" />
            XmlSchemaAttribute messageNumber = new XmlSchemaAttribute();

            messageNumber.Name           = ProtocolStrings.SchemaNames.AppSequenceMessageNumber;
            messageNumber.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.UnsignedIntType;
            messageNumber.Use            = XmlSchemaUse.Required;

            // <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();

            anyAttribue.Namespace       = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            contentRestriction.Attributes.Add(instanceId);
            contentRestriction.Attributes.Add(sequenceId);
            contentRestriction.Attributes.Add(messageNumber);
            contentRestriction.AnyAttribute = anyAttribue;

            schema.Items.Add(appSequenceType);
        }
Ejemplo n.º 13
0
 private void Write33_XmlSchemaAnyAttribute(XmlSchemaAnyAttribute o)
 {
     if (o != null)
     {
         this.WriteStartElement("anyAttribute");
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttribute("namespace", "", ToString(o.NamespaceList));
         XmlSchemaContentProcessing v = (o.ProcessContents == XmlSchemaContentProcessing.None) ? XmlSchemaContentProcessing.Strict : o.ProcessContents;
         this.WriteAttribute("processContents", "", this.Write34_XmlSchemaContentProcessing(v));
         this.WriteAttributes(o.UnhandledAttributes, o);
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteEndElement();
     }
 }
Ejemplo n.º 14
0
        /// <summary>
        /// Creates the schema type representing a macro expansion
        /// </summary>
        /// <returns>Type definition for expanding a macro</returns>
        static XmlSchemaType CreateExpandType()
        {
            XmlSchemaAnyAttribute AnyAttribute = new XmlSchemaAnyAttribute();

            AnyAttribute.ProcessContents = XmlSchemaContentProcessing.Skip;

            XmlSchemaComplexType PropertyType = new XmlSchemaComplexType();

            PropertyType.Name = GetTypeName(ScriptSchemaStandardType.Expand);
            PropertyType.Attributes.Add(CreateSchemaAttribute("Name", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Required));
            PropertyType.Attributes.Add(CreateSchemaAttribute("If", ScriptSchemaStandardType.BalancedString, XmlSchemaUse.Optional));
            PropertyType.AnyAttribute = AnyAttribute;
            return(PropertyType);
        }
Ejemplo n.º 15
0
    public static void Main()
    {
        XmlSchema schema = new XmlSchema();

        // <element name="stringElementWithAnyAttribute">
        XmlSchemaElement element = new XmlSchemaElement();

        schema.Items.Add(element);
        element.Name = "stringElementWithAnyAttribute";

        // <complexType>
        XmlSchemaComplexType complexType = new XmlSchemaComplexType();

        element.SchemaType = complexType;

        // <simpleContent>
        XmlSchemaSimpleContent simpleContent = new XmlSchemaSimpleContent();

        complexType.ContentModel = simpleContent;

        // <extension base="xs:string">
        XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension();

        simpleContent.Content  = extension;
        extension.BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");

        // <anyAttribute namespace="##targetNamespace"/>
        XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

        extension.AnyAttribute = anyAttribute;
        anyAttribute.Namespace = "##targetNamespace";

        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);
    }
Ejemplo n.º 16
0
        internal XSWildcard(XmlSchemaAnyAttribute xmlAnyAttribute)
        {
            _wildcard = xmlAnyAttribute;

            if (_wildcard.Annotation is XmlSchemaAnnotation annotation)
            {
                _annotation = XMLSchemaSerializer.CreateXSAnnotation(annotation);
                _annotation.BindToContainer(RootContainer, this);
            }

            _processContents = (XSProcessContents)xmlAnyAttribute.ProcessContents;
            _namespace = xmlAnyAttribute.Namespace;

            SetNamespaceConstraint();
        }
Ejemplo n.º 17
0
        static void AddProbeType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ProbeType">
            XmlSchemaComplexType probeType = new XmlSchemaComplexType();

            probeType.Name = ProtocolStrings.SchemaNames.ProbeType;

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

            //     <xs:element ref="tns:Types" minOccurs="0" />
            XmlSchemaElement typesElement = new XmlSchemaElement();

            typesElement.RefName   = discoveryVersion.Implementation.QualifiedNames.TypesElement;
            typesElement.MinOccurs = 0;

            //     <xs:element ref="tns:Scopes" minOccurs="0" />
            XmlSchemaElement scopesElement = new XmlSchemaElement();

            scopesElement.RefName   = discoveryVersion.Implementation.QualifiedNames.ScopesElement;
            scopesElement.MinOccurs = 0;

            //     <xs:any namespace="##other" processContents="lax" minOccurs="0" maxOccurs="unbounded" />
            XmlSchemaAny any = new XmlSchemaAny();

            any.Namespace       = "##other";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            any.MinOccurs       = 0;
            any.MaxOccurs       = decimal.MaxValue;

            //   </xs:sequence>
            probeTypeSequence.Items.Add(typesElement);
            probeTypeSequence.Items.Add(scopesElement);
            probeTypeSequence.Items.Add(any);

            //   <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();

            anyAttribue.Namespace       = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            // </xs:complexType>
            probeType.Particle     = probeTypeSequence;
            probeType.AnyAttribute = anyAttribue;

            schema.Items.Add(probeType);
        }
Ejemplo n.º 18
0
        void Write33_XmlSchemaAnyAttribute(XmlSchemaAnyAttribute o)
        {
            if ((object)o == null)
            {
                return;
            }
            WriteStartElement("anyAttribute");

            WriteAttribute(@"id", @"", ((System.String)o.@Id));
            WriteAttribute("namespace", "", ToString(o.NamespaceList));
            XmlSchemaContentProcessing process = o.@ProcessContents == XmlSchemaContentProcessing.@None ? XmlSchemaContentProcessing.Strict : o.@ProcessContents;

            WriteAttribute(@"processContents", @"", Write34_XmlSchemaContentProcessing(process));
            WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
            Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
            WriteEndElement();
        }
Ejemplo n.º 19
0
        void WriteAttributes(XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
        {
            foreach (XmlSchemaObject at in atts)
            {
                if (at is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr    = (XmlSchemaAttribute)at;
                    XmlSchemaAttribute refAttr = attr;

                    // refAttr.Form; TODO

                    if (!attr.RefName.IsEmpty)
                    {
                        refAttr = FindRefAttribute(attr.RefName);
                        if (refAttr == null)
                        {
                            throw new InvalidOperationException("Global attribute not found: " + attr.RefName);
                        }
                    }

                    string val;
                    if (!refAttr.SchemaTypeName.IsEmpty)
                    {
                        val = FindBuiltInType(refAttr.SchemaTypeName);
                    }
                    else
                    {
                        val = FindBuiltInType((XmlSchemaSimpleType)refAttr.SchemaType);
                    }

                    xtw.WriteAttributeString(refAttr.Name, val);
                }
                else if (at is XmlSchemaAttributeGroupRef)
                {
                    XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
                    XmlSchemaAttributeGroup    grp  = (XmlSchemaAttributeGroup)schemas.Find(gref.RefName, typeof(XmlSchemaAttributeGroup));
                    WriteAttributes(xtw, grp.Attributes, grp.AnyAttribute);
                }
            }

            if (anyat != null)
            {
                xtw.WriteAttributeString("custom-attribute", "value");
            }
        }
        public void v2(string ns1, string ns2, string attrNs, int expectedError, string expectedNs = null)
        {
            XmlSchemaSet xss = new XmlSchemaSet();

            xss.XmlResolver             = new XmlUrlResolver();
            xss.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            xss.Add(GetUnionSchema(ns1, ns2, attrNs));
            xss.Compile();

            Assert.Equal(expectedError, _errorCount);

            // .NET Framework does not set the namespace property for intersections and unions
            if (!PlatformDetection.IsNetFramework && expectedNs != null)
            {
                XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t1", attrNs)]).AttributeWildcard;
                CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace);
            }
        }
Ejemplo n.º 21
0
        private void RegisterExtensionAttribute(XmlSchemaAnyAttribute parent, XmlSchemaObject obj)
        {
            // Add object to parent's extension attributes.

            List <XmlSchemaObject> attributes;

            if (!_extensionAttributes.TryGetValue(parent, out attributes))
            {
                attributes = new List <XmlSchemaObject>();
                _extensionAttributes.Add(parent, attributes);
            }

            attributes.Add(obj);

            // Add parent to object's parents.

            RegisterParent(obj, parent);
        }
Ejemplo n.º 22
0
        private XmlSchemaSequence ExtractAttributesAndElements(JsonSchema jSchema, XmlSchemaComplexType complexType)
        {
            if (jSchema == null || jSchema.Properties() == null)
            {
                return(null);
            }

            List <string> requiredProperties = GetterExtensions.Required(jSchema);

            XmlSchemaSequence sequence = new XmlSchemaSequence();

            foreach (KeyValuePair <string, JsonSchema> property in jSchema.Properties())
            {
                string     propertyName = property.Key;
                JsonSchema propertyType = property.Value;

                string xsdType = propertyType.OtherData.TryGetString("@xsdType");
                if (xsdType != null && xsdType.Equals("XmlAttribute"))
                {
                    XmlSchemaAttribute attribute = ExtractAttribute(propertyName, propertyType);
                    if (requiredProperties != null && requiredProperties.Contains(propertyName))
                    {
                        attribute.Use = XmlSchemaUse.Required;
                    }

                    complexType.Attributes.Add(attribute);
                }
                else
                {
                    sequence.Items.Add(ExtractElementSequence(propertyName, propertyType, jSchema));
                }
            }

            bool?xsdAnyAttribute = jSchema.OtherData.TryGetBoolean("@xsdAnyAttribute");

            if (xsdAnyAttribute == true)
            {
                XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();
                anyAttribute.Namespace   = "##targetNamespace";
                complexType.AnyAttribute = anyAttribute;
            }

            return(sequence);
        }
        /// <summary>Determines whether the specified <paramref name="attribute"/> is expected.</summary>
        /// <param name="attribute">Attribute to check.</param>
        /// <param name="expectedAttributes">Expected attributes (possibly empty).</param>
        /// <param name="anyAttribute">anyAttribute schema for a complex type element (possibly null).</param>
        /// <returns>true if the attribute is expected; false otherwise.</returns>
        private static bool IsAttributeExpected(XAttribute attribute, XmlSchemaAnyAttribute anyAttribute, XmlSchemaAttribute[] expectedAttributes)
        {
            Debug.Assert(attribute != null, "attribute != null");
            Debug.Assert(expectedAttributes != null, "expectedAttributes != null");
            Debug.Assert(expectedAttributes.All(a => a.Form != XmlSchemaForm.Qualified), "expectedAttributes.All(a => a.Form != XmlSchemaForm.Qualified)");

            var name = ToQualifiedName(attribute.Name);

            if (name.Namespace.Length == 0)
            {
                foreach (var expected in expectedAttributes)
                {
                    if (expected.Name == name.Name)
                    {
                        return(true);
                    }
                }
            }

            if (anyAttribute != null)
            {
                Debug.Assert(
                    anyAttribute.Namespace == "##any" || anyAttribute.Namespace == "##other",
                    "anyAttribute.Namespace == '##any' || '##other' -- otherwise CSDL XSD resource was changed");
                if (anyAttribute.Namespace == "##any")
                {
                    return(true);
                }
                else
                {
                    string attributeNamespace = attribute.Name.NamespaceName;
                    if (attributeNamespace.Length > 0 && attributeNamespace != GetTargetNamespace(anyAttribute))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private static XmlSchemaComplexType CreateOuterType()
        {
            XmlSchemaAttribute item = new XmlSchemaAttribute {
                Name           = "Dialect",
                SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema"),
                Use            = XmlSchemaUse.Optional
            };
            XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension {
                BaseTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema")
            };

            extension.Attributes.Add(item);
            XmlSchemaSimpleContent content = new XmlSchemaSimpleContent {
                Content = extension
            };
            XmlSchemaComplexType type = new XmlSchemaComplexType {
                ContentModel = content
            };
            XmlSchemaElement element = new XmlSchemaElement {
                Name       = "XPath",
                SchemaType = type
            };
            XmlSchemaSequence sequence = new XmlSchemaSequence();

            sequence.Items.Add(element);
            XmlSchemaAttribute attribute2 = new XmlSchemaAttribute {
                Name           = "NodeQuota",
                SchemaTypeName = new XmlQualifiedName("int", "http://www.w3.org/2001/XMLSchema"),
                Use            = XmlSchemaUse.Optional
            };
            XmlSchemaAnyAttribute attribute3 = new XmlSchemaAnyAttribute();
            XmlSchemaComplexType  type2      = new XmlSchemaComplexType {
                Name     = "XPathMessageFilter",
                Particle = sequence
            };

            type2.Attributes.Add(attribute2);
            type2.AnyAttribute = attribute3;
            return(type2);
        }
Ejemplo n.º 25
0
        static void AddScopesType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            // <xs:complexType name="ScopesType">
            XmlSchemaComplexType scopesType = new XmlSchemaComplexType();

            scopesType.Name = ProtocolStrings.SchemaNames.ScopesType;

            //    <xs:simpleContent>
            XmlSchemaSimpleContent scopesTypeContent = new XmlSchemaSimpleContent();

            //       <xs:extension base="tns:UriListType">
            XmlSchemaSimpleContentExtension scopesTypeContentExtension = new XmlSchemaSimpleContentExtension();

            scopesTypeContentExtension.BaseTypeName = discoveryVersion.Implementation.QualifiedNames.UriListType;

            //          <xs:attribute name="MatchBy" type="xs:anyURI" />
            XmlSchemaAttribute matchBy = new XmlSchemaAttribute();

            matchBy.Name           = ProtocolStrings.SchemaNames.MatchByAttribute;
            matchBy.SchemaTypeName = discoveryVersion.Implementation.QualifiedNames.AnyUriType;

            //          <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribute = new XmlSchemaAnyAttribute();

            anyAttribute.Namespace       = "##other";
            anyAttribute.ProcessContents = XmlSchemaContentProcessing.Lax;

            //       </xs:extension>
            scopesTypeContentExtension.Attributes.Add(matchBy);
            scopesTypeContentExtension.AnyAttribute = anyAttribute;

            //    </xs:simpleContent>
            scopesTypeContent.Content = scopesTypeContentExtension;

            // <xs:complexType name="ScopesType">
            scopesType.ContentModel = scopesTypeContent;

            schema.Items.Add(scopesType);
        }
Ejemplo n.º 26
0
        static void AddResolveType(DiscoveryVersion discoveryVersion, XmlSchema schema)
        {
            //<xs:complexType name="ResolveType" >
            XmlSchemaComplexType resolveType = new XmlSchemaComplexType();

            resolveType.Name = ProtocolStrings.SchemaNames.ResolveType;

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

            //     <xs:element ref="wsa:EndpointReference" />
            XmlSchemaElement eprElement = new XmlSchemaElement();

            eprElement.RefName = discoveryVersion.Implementation.QualifiedNames.EprElement;

            //     <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##other" processContents="lax" />
            XmlSchemaAny any = new XmlSchemaAny();

            any.Namespace       = "##other";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;
            any.MinOccurs       = 0;
            any.MaxOccurs       = decimal.MaxValue;

            resolveSequence.Items.Add(eprElement);
            resolveSequence.Items.Add(any);

            //   <xs:anyAttribute namespace="##other" processContents="lax" />
            XmlSchemaAnyAttribute anyAttribue = new XmlSchemaAnyAttribute();

            anyAttribue.Namespace       = "##other";
            anyAttribue.ProcessContents = XmlSchemaContentProcessing.Lax;

            // </xs:complexType>
            resolveType.Particle     = resolveSequence;
            resolveType.AnyAttribute = anyAttribue;

            schema.Items.Add(resolveType);
        }
        private XmlSchemaAttribute FindSchemaInfo(XmlAttribute attributeToValidate)
        {
            XmlElement           ownerElement = attributeToValidate.OwnerElement;
            XmlSchemaObject      schemaObject = this.FindSchemaInfo(ownerElement);
            XmlSchemaComplexType complexType  = this.GetComplexType(schemaObject);

            if (complexType == null)
            {
                return(null);
            }
            XmlQualifiedName   qname     = new XmlQualifiedName(attributeToValidate.LocalName, attributeToValidate.NamespaceURI);
            XmlSchemaAttribute attribute = complexType.AttributeUses[qname] as XmlSchemaAttribute;

            if (attribute == null)
            {
                XmlSchemaAnyAttribute attributeWildcard = complexType.AttributeWildcard;
                if ((attributeWildcard != null) && attributeWildcard.NamespaceList.Allows(qname))
                {
                    attribute = this.schemas.GlobalAttributes[qname] as XmlSchemaAttribute;
                }
            }
            return(attribute);
        }
Ejemplo n.º 28
0
        internal static XmlSchema BuildSchema(DiscoveryVersion version)
        {
            var schema = new XmlSchema()
            {
                TargetNamespace = version.Namespace
            };
            string addrNS = "http://www.w3.org/2005/08/addressing";

            var anyAttr = new XmlSchemaAnyAttribute()
            {
                Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax
            };

            var resolvePart = new XmlSchemaSequence();

            resolvePart.Items.Add(new XmlSchemaElement()
            {
                RefName = new XmlQualifiedName("EndpointReference", addrNS), MinOccurs = 0
            });
            resolvePart.Items.Add(new XmlSchemaAny()
            {
                MinOccurs = 0, MaxOccursString = "unbounded", Namespace = "##other", ProcessContents = XmlSchemaContentProcessing.Lax
            });
            var ct = new XmlSchemaComplexType()
            {
                Name = "ResolveType", Particle = resolvePart, AnyAttribute = anyAttr
            };

            schema.Includes.Add(new XmlSchemaImport()
            {
                Namespace = addrNS
            });
            schema.Items.Add(ct);

            return(schema);
        }
Ejemplo n.º 29
0
        private void GenerateAttributeWildCard(XmlSchemaComplexType ct, InstanceElement elem)
        {
            char[]             whitespace = new char[] { ' ', '\t', '\n', '\r' };
            InstanceAttribute  attr       = null;
            XmlSchemaAttribute anyAttr    = null;

            XmlSchemaAnyAttribute attributeWildCard = ct.AttributeWildcard;
            XmlSchemaObjectTable  attributes        = ct.AttributeUses;

            string namespaceList = attributeWildCard.Namespace;

            if (namespaceList == null)
            {
                namespaceList = "##any";
            }
            if (attributeWildCard.ProcessContents == XmlSchemaContentProcessing.Skip || attributeWildCard.ProcessContents == XmlSchemaContentProcessing.Lax)
            {
                if (namespaceList == "##any" || namespaceList == "##targetNamespace")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", rootTargetNamespace));
                }
                else if (namespaceList == "##local")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", string.Empty));
                }
                else if (namespaceList == "##other")
                {
                    attr = new InstanceAttribute(new XmlQualifiedName("any_Attr", "otherNS"));
                }
                if (attr != null)
                {
                    attr.ValueGenerator = XmlValueGenerator.AnySimpleTypeGenerator;
                    elem.AddAttribute(attr);
                    return;
                }
            }
            switch (namespaceList)
            {
            case "##any":
            case "##targetNamespace":
                anyAttr = GetAttributeFromNS(rootTargetNamespace, attributes);
                break;

            case "##other":
                XmlSchema anySchema = GetParentSchema(attributeWildCard);
                anyAttr = GetAttributeFromNS(anySchema.TargetNamespace, true, attributes);
                break;

            case "##local":      //Shd get local elements in some schema
                anyAttr = GetAttributeFromNS(string.Empty, attributes);
                break;

            default:
                foreach (string ns in attributeWildCard.Namespace.Split(whitespace))
                {
                    if (ns == "##local")
                    {
                        anyAttr = GetAttributeFromNS(string.Empty, attributes);
                    }
                    else if (ns == "##targetNamespace")
                    {
                        anyAttr = GetAttributeFromNS(rootTargetNamespace, attributes);
                    }
                    else
                    {
                        anyAttr = GetAttributeFromNS(ns, attributes);
                    }
                    if (anyAttr != null)       //Found match
                    {
                        break;
                    }
                }
                break;
            }
            if (anyAttr != null)
            {
                GenerateInstanceAttribute(anyAttr, elem);
            }
            else                              //Write comment in generated XML that match for wild card cd not be found.
            {
                if (elem.Comment.Length == 0) //For multiple attribute wildcards in the same element, generate comment only once
                {
                    elem.Comment.Append(" Attribute Wild card could not be matched. Generated XML may not be valid. ");
                }
            }
        }
Ejemplo n.º 30
0
        void ExportMembersMapSchema(XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute)
        {
            particle = null;
            XmlSchemaSequence seq = new XmlSchemaSequence();

            ICollection members = map.ElementMembers;

            if (members != null && !map.HasSimpleContent)
            {
                foreach (XmlTypeMapMemberElement member in members)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, member))
                    {
                        continue;
                    }

                    Type memType = member.GetType();
                    if (memType == typeof(XmlTypeMapMemberFlatList))
                    {
                        XmlSchemaParticle part = GetSchemaArrayElement(schema, member.ElementInfo);
                        if (part != null)
                        {
                            seq.Items.Add(part);
                        }
                    }
                    else if (memType == typeof(XmlTypeMapMemberAnyElement))
                    {
                        seq.Items.Add(GetSchemaArrayElement(schema, member.ElementInfo));
                    }
                    else if (memType == typeof(XmlTypeMapMemberElement))
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo [0],
                                         member.DefaultValue, true, new XmlSchemaObjectContainer(seq));
                    }
                    else
                    {
                        GetSchemaElement(schema, (XmlTypeMapElementInfo)member.ElementInfo[0],
                                         true, new XmlSchemaObjectContainer(seq));
                    }
                }
            }

            if (seq.Items.Count > 0)
            {
                particle = seq;
            }

            // Write attributes

            ICollection attributes = map.AttributeMembers;

            if (attributes != null)
            {
                foreach (XmlTypeMapMemberAttribute attr in attributes)
                {
                    if (baseMap != null && DefinedInBaseMap(baseMap, attr))
                    {
                        continue;
                    }
                    outAttributes.Add(GetSchemaAttribute(schema, attr, true));
                }
            }

            XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember;

            if (anyAttrMember != null)
            {
                anyAttribute = new XmlSchemaAnyAttribute();
            }
            else
            {
                anyAttribute = null;
            }
        }