xuri / xgen

XSD (XML Schema Definition) parser and Go/C/Java/Rust/TypeScript code generator
BSD 3-Clause "New" or "Revised" License
340 stars 80 forks source link

How to handle the actual text content of an element? #24

Closed syvanpera closed 3 years ago

syvanpera commented 3 years ago

Is your feature request related to a problem? Please describe.

Looks like the generated types don't have any place for the actual text content of an element

Describe the solution you'd like

A field should be generated for the element text. For example xxxText where xxx is the element name.

Additional context Here's an example xsd:

<?xml version="1.0" encoding="utf-8"?>
<xsd:schema attributeFormDefault="unqualified" elementFormDefault="qualified" version="1.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <xsd:complexType name="SomeType">
    <xsd:simpleContent>
      <xsd:extension base="xsd:string">
        <xsd:attribute ref="SomeTypeId" use="required" />
      </xsd:extension>
    </xsd:simpleContent>
  </xsd:complexType>
</xsd:schema>

And the generated (TypeScript) types:

// Code generated by xgen. DO NOT EDIT.

// SomeType ...
export class SomeType {
    SomeTypeIdAttr: SomeTypeId;
}

Maybe change to something like:

export class SomeType {
    SomeTypeIdAttr: SomeTypeId;
        SomeTypeText: string
}

The xxxText might be too generic, but something like that

syvanpera commented 3 years ago

Ah this seems to be a duplicate for #7