XmlSchemaClassGenerator icon indicating copy to clipboard operation
XmlSchemaClassGenerator copied to clipboard

QUESTION: Generate as XmlCdataSection for primate strings/named properties?

Open mistyn8 opened this issue 9 months ago • 1 comments

Is there a way to have specified properties, or all primitive strings generate as XMLCdataSections?

Currently, I'm having to generate an additional partial class and remember to add an [XMLIgnore] and match the order in the generated partial class (each time I regenerate), which is a little cumbersome but works.

Any better approaches?

Additional partial

        /// <summary>
        /// Update the generated code to ignore the default
        ///  [XmlIgnore] public string summary
        /// </summary>
        [System.ComponentModel.DataAnnotations.MaxLengthAttribute(1000)]
        [System.ComponentModel.DataAnnotations.RequiredAttribute(AllowEmptyStrings=true)]
        [System.Xml.Serialization.XmlElementAttribute("summary", Order = 10, Form = System.Xml.Schema.XmlSchemaForm.Unqualified)]
        public XmlCDataSection SummaryCData
        {
            get
            {
                var doc = new XmlDocument();
                return doc.CreateCDataSection(Summary);
            }
            set
            {
                Summary = value?.Value;
            }
        }

Generated

 /// <summary>
 /// <para xml:lang="en">Maximum length: 1000.</para>
 /// </summary>
 [System.ComponentModel.DataAnnotations.MaxLengthAttribute(1000)]
 [System.ComponentModel.DataAnnotations.RequiredAttribute(AllowEmptyStrings=true)]
 [System.Xml.Serialization.XmlElementAttribute("summary", Order=10, Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
 [XmlIgnore]
 public string Summary { get; set; }

mistyn8 avatar Mar 05 '25 12:03 mistyn8

There is currently no support for this. PRs welcome 😄

mganss avatar Mar 06 '25 19:03 mganss