Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AnyAttribute in AttributeGroup are ignored #531

Closed
mariochr opened this issue Oct 31, 2024 · 0 comments
Closed

AnyAttribute in AttributeGroup are ignored #531

mariochr opened this issue Oct 31, 2024 · 0 comments

Comments

@mariochr
Copy link

mariochr commented Oct 31, 2024

I am getting the following xsd (simplified) with different use of anyAttribute:

<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
 
 <!-- With attribute group it does not work -->
 <xs:complexType name="SaleType">
    <xs:attributeGroup ref="anyAttribute" />
 </xs:complexType> 
 
 <!-- Without attribute group it does work -->
 <xs:complexType name="OrderType">
    <xs:anyAttribute namespace="##other" />
 </xs:complexType> 
 
 <!-- If used with simple content it works-->
  <xs:complexType name="PurchaseType">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attributeGroup ref="anyAttribute" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

<!-- Attribute group with anyAttribute -->
  <xs:attributeGroup name="anyAttribute">
    <xs:anyAttribute namespace="##other" />
  </xs:attributeGroup>

The problem is that only with the first one SaleType no code for anyAttribute is generated. Why is that?
As soon as I have an attributeGroup with anyAttribute in it no Code is generated for it, but If I add the anyAttribute in the complex type directly (OrderType) or if I have it in a simpleContent (complexContent does not work iirc) (PurchaseType) it works...

As a workaround I modify the xsd and put the anyAttribute in directly but there will be new versions in the future and I would rather avoid doing that.

Here the generated code (SaleType is completely empty except the interface which is also empty):

//------------------------------------------------------------------------------
// <auto-generated>
//     This code was generated by a tool.
//     Runtime Version:4.0.30319.42000
//
//     Changes to this file may cause incorrect behavior and will be lost if
//     the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

// This code was generated by XmlSchemaClassGenerator version 2.1.1164.0
namespace Order
{
    
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("SaleType", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class SaleType : IanyAttribute
    {
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    public partial interface IanyAttribute
    {
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("OrderType", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class OrderType
    {
        
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        private System.Collections.Generic.List<System.Xml.XmlAttribute> _anyAttribute;
        
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Collections.Generic.List<System.Xml.XmlAttribute> AnyAttribute
        {
            get
            {
                return _anyAttribute;
            }
            private set
            {
                _anyAttribute = value;
            }
        }
        
        /// <summary>
        /// <para xml:lang="en">Gets a value indicating whether the AnyAttribute collection is empty.</para>
        /// </summary>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool AnyAttributeSpecified
        {
            get
            {
                return (this.AnyAttribute.Count != 0);
            }
        }
        
        /// <summary>
        /// <para xml:lang="en">Initializes a new instance of the <see cref="OrderType" /> class.</para>
        /// </summary>
        public OrderType()
        {
            this._anyAttribute = new System.Collections.Generic.List<System.Xml.XmlAttribute>();
        }
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("PurchaseType", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class PurchaseType : IanyAttribute
    {
        
        /// <summary>
        /// <para xml:lang="en">Gets or sets the text value.</para>
        /// </summary>
        [System.Xml.Serialization.XmlTextAttribute()]
        public string Value { get; set; }
        
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        private System.Collections.Generic.List<System.Xml.XmlAttribute> _anyAttribute;
        
        [System.Xml.Serialization.XmlAnyAttributeAttribute()]
        public System.Collections.Generic.List<System.Xml.XmlAttribute> AnyAttribute
        {
            get
            {
                return _anyAttribute;
            }
            private set
            {
                _anyAttribute = value;
            }
        }
        
        /// <summary>
        /// <para xml:lang="en">Gets a value indicating whether the AnyAttribute collection is empty.</para>
        /// </summary>
        [System.Xml.Serialization.XmlIgnoreAttribute()]
        public bool AnyAttributeSpecified
        {
            get
            {
                return (this.AnyAttribute.Count != 0);
            }
        }
        
        /// <summary>
        /// <para xml:lang="en">Initializes a new instance of the <see cref="PurchaseType" /> class.</para>
        /// </summary>
        public PurchaseType()
        {
            this._anyAttribute = new System.Collections.Generic.List<System.Xml.XmlAttribute>();
        }
    }
}

Edit:

I found another weird case with complexContent:

  <xs:complexType name="StockTypeBase" />
  
  <xs:complexType name="StockType1">
    <xs:complexContent>
      <xs:extension base="StockTypeBase">	  
	 <xs:anyAttribute namespace="##other" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>
  
  <xs:complexType name="StockType2">
    <xs:complexContent>
      <xs:extension base="StockTypeBase">
        <xs:attributeGroup ref="anyAttribute" />
      </xs:extension>
    </xs:complexContent>
  </xs:complexType>

StockType1has the anyAttribute while StockType2 has it with the attributeGroup.

But in the produced code all types are empty:

    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("StockTypeBase", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(StockType1))]
    [System.Xml.Serialization.XmlIncludeAttribute(typeof(StockType2))]
    public partial class StockTypeBase
    {
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("StockType1", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class StockType1 : StockTypeBase
    {
    }
    
    [System.CodeDom.Compiler.GeneratedCodeAttribute("XmlSchemaClassGenerator", "2.1.1164.0")]
    [System.SerializableAttribute()]
    [System.Xml.Serialization.XmlTypeAttribute("StockType2", Namespace="")]
    [System.Diagnostics.DebuggerStepThroughAttribute()]
    [System.ComponentModel.DesignerCategoryAttribute("code")]
    public partial class StockType2 : StockTypeBase, IanyAttribute
    {
    }
@mganss mganss closed this as completed in e44cd71 Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant