xsd元素名称的类型

时间:2016-12-28 17:03:49

标签: xml xsd

我有一个复杂类型的层次结构。

例如: 抽象类型地址与元素StreetNumber,StreetName和PostalCode 具有基地址的具体类型HomeAddress 具有基地址的具体类型BusinessAddress

HomeAddress和BusinessAddress类型没有任何其他元素,只有类型不同。

我的XML中可能有多种地址类型吗?

<HomeAddress>
...
</HomeAddress>

<HomeAddress>
...
</HomeAddress>

在xsd:

<xs:element name="address" type="Address" maxOccurs="unbounded"/>

我希望元素名称基于实际类型是动态的。

1 个答案:

答案 0 :(得分:0)

使用“abstract”属性和xs:extension元素:

class Batting(models.Model):
  player = models.ForeignKey(
    'Player',
    on_delete=models.CASCADE,
    null=True,
    )
  game = models.ForeignKey(
    'Game',
    on_delete=models.CASCADE,
    null=True,
    blank=True,
    )
  season = models.ForeignKey(
    'Season', 
    on_delete=models.CASCADE,
    null=True,
    )
  games_played = models.IntegerField(
    blank=True,
    default=1,
    )
  plate_appearances = models.IntegerField(
    blank=True,
    default=0,
    )
  at_bats = models.DecimalField(
    default=0,
    max_digits=6,
    decimal_places=3,
    )
  hits = models.DecimalField(
    blank=True,
    max_digits=6,
    decimal_places=3,
    default=0,
    )
  ...
  batting_average = models.DecimalField(
    max_digits=6,
    decimal_places=3,
    editable=False,
    null=True
    )
  slugging_percentage = models.DecimalField(
    max_digits=6,
    decimal_places=3,
    editable=False,
    null=True
    )
  on_base_percentage = models.DecimalField(
    max_digits=6,
    decimal_places=3,
    editable=False,
    null=True
    )
  on_base_plus_slugging_percentage = models.DecimalField(
    max_digits=6,
    decimal_places=3,
    editable=False,
    null=True
    )

  def save(self, *args, **kwargs):
        self.total_bases = self.singles + (self.doubles * 2) + (self.triples * 3) + (self.home_runs * 4)
        self.extra_base_hits = self.doubles + self.triples + self.home_runs
        self.batting_average = float(self.hits) / float(self.at_bats)
        self.slugging_percentage = self.total_bases / float(self.at_bats)
        self.on_base_percentage = (self.hits + self.base_on_balls + self.hit_by_pitch) / float(self.at_bats + self.base_on_balls + self.sacrifice_flys + self.hit_by_pitch)
        self.on_base_plus_slugging_percentage = (self.hits + self.base_on_balls + self.hit_by_pitch) / float(self.at_bats + self.base_on_balls + self.sacrifice_flys + self.hit_by_pitch)
        super(Batting, self).save(*args, **kwargs)

  class Meta:
    verbose_name = u'Batting Stat'
    verbose_name_plural = u'Batting Stats'

  def __unicode__(self):
    return self.player.last_name