[XML] enumeratie probleem

Pagina: 1
Acties:

  • Alarmnummer
  • Registratie: Juli 2001
  • Laatst online: 09-07-2024
Ik moet voor relaties die ik opsla in XML ook de cardinaliteit vermelden. Dit doe ik op dit moment met een string, maar er kunnen maar 4 mogelijke strings staan:
one to one
one to many
many to one
many to many

Is het mogelijk om in het schema aan te geven dat je een soortement van enumeratie hebt ipv een string? Zodat je met het schema bestand dit al kan controleren?

ps: is nog redelijke XML/XSL/Schema noob.

  • mbravenboer
  • Registratie: Januari 2000
  • Laatst online: 06-11-2025
Ja, dat is mogelijk (alhoewel ik het liever met elementen zou doen dan met strings in attributen).

Bijv:
code:
1
2
3
4
5
6
7
8
<relation>
    <from>
      <one/>
    </from>
    <to>
      <many/>
    </to>
</relation>

Beetje verbose, maar wel duidelijk :+ . Vooral ook in je schema.

Als je het toch met enumeraties en attributen wilt oplossen moet je eens kijken op slides 51 van de XML Schema tutorial op http://www.xfront.com :
code:
1
2
3
4
5
6
7
<xsd:simpleType name="US-Flag-Colors">
    <xsd:restriction base="xsd:string">
      <xsd:enumeration value="red"/>
      <xsd:enumeration value="white"/>
      <xsd:enumeration value="blue"/>
    </xsd:restriction>
</xsd:simpleType>

Simple he? ;) .

Blog, Stratego/XT: Program Transformation, SDF: Syntax Definition, Nix: Software Deployment


  • Alarmnummer
  • Registratie: Juli 2001
  • Laatst online: 09-07-2024
thanx :)

  • Dennis
  • Registratie: Februari 2001
  • Laatst online: 23:41
Alarmnummer: je opent vaak topics, maar heel veel topics zijn altijd reuze-interessant :) :)