将UML转换为JSON模式和XSD [英] UML into JSON Schema and XSD

查看:189
本文介绍了将UML转换为JSON模式和XSD的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了简单的UML图,它是电影院更大图的一部分.

I created simple UML diagram which is part of bigger diagram of cinema.

图片

基于此图,我创建了Json Schema和XSD文件

Based on this diagram I created Json Schema and XSD files

Json模式:

-> movieSchema.json

-> movieSchema.json

    {
    "type": "object",
    "required": true,
    "properties": {
        "idOfMovie": {
            "type": "integer",
            "required": true
        },
        "title": {
            "type": "string",
            "required": true
        },
        "is3D": {
            "type": "boolean",
            "required": true
        },
        "yearOfProduction": {
            "type": "integer",
            "required": true
        },
        "ageCategory": {
            "type": "integer",
            "required": true
        },
        "description": {
            "type": "string",
            "required": true
        }
    } 
}

-> missionSchema.json

-> emissionSchema.json

 {
    "type": "object",
    "required": true,
    "properties": {
        "idOfEmission": {
            "type": "integer",
            "required": true
        },
        "idOfMovie": {
            "type": "integer",
            "required": true
        },
        "dateOfEmission": {
            "type": "string",
            "required": true
        },
        "idOfHall": {
            "type": "integer",
            "required": true
        }
    }
}

和XSD:

-> movie.xsd

->movie.xsd

    <?xml version="1.0" encoding="UTF-8"?>

<schema version="1.0"
           xmlns="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:x-test" xmlns:tst='urn:x-test' 
           elementFormDefault="qualified">

    <element name="movie" type="tst:movieType"/> 
    <complexType name="movieType">
        <sequence>
            <element name="title" type="string" use="required" />
            <element name="is3D" type="boolean" use="required" />
            <element name="yearOfProduction" type="integer" use="required" />
            <element name="ageCategory" type="integer" use="required" />
            <element name="description" type="string" use="required" />
        </sequence>
        <attribute name="idOfMovie" type="integer" use="required"/>
    </complexType>

    <element name="movies" type="tst:moviesType"/> 
    <complexType name="moviesType">
        <sequence minOccurs="0" maxOccurs="unbounded">
            <element ref="tst:movie"/>
        </sequence>
    </complexType>
</schema>

-> emission.xsd

->emission.xsd

<?xml version="1.0" encoding="UTF-8"?>

<schema version="1.0"
           xmlns="http://www.w3.org/2001/XMLSchema"
           targetNamespace="urn:x-test" xmlns:tst='urn:x-test' 
           elementFormDefault="qualified">

    <element name="emission" type="tst:emissionType"/> 
    <complexType name="emissionType">
        <sequence>
            <element name="idOfMovie" type="integer" use="required" />
            <element name="dateOfEmission" type="string" use="required" />
            <element name="idOfHall" type="integer" use="required" />
        </sequence>
        <attribute name="idOfEmission" type="integer" use="required"/>
    </complexType>

    <element name="emissions" type="tst:emissionsType"/> 
    <complexType name="emissionsType">
        <sequence minOccurs="0" maxOccurs="unbounded">
            <element ref="tst:emission"/>
        </sequence>
    </complexType>
</schema>

文件和数据:

-> movies.json

-->movies.json

    [
    {
        "idOfMovie": 1,
        "title": "...",
        "is3D": TRUE,
        "yearOfProduction": 2015,
        "ageCategory": 7,
        "description": "..."
    },
    {
        "idOfMovie": 2,
        "title": "...",
        "is3D": TRUE,
        "yearOfProduction": 2015,
        "ageCategory": 12,
        "description": "..."
    },
    {
        "idOfMovie": 3,
        "title": "...",
        "is3D": FALSE,
        "yearOfProduction": 2015,
        "ageCategory": 12,
        "description": "..."
    }
]

-> missions.json

--> emissions.json

    [
    {
        "idOfEmission": 1,
        "idOfMovie": 1,
        "dateOfEmission": "01-03-2015-14:00",
        "idOfHall":  2
    },
    {
        "idOfEmission": 2,
        "idOfMovie": 1,
        "dateOfEmission": "02-03-2015-14:00", 
        "idOfHall":  2
    },
    {
        "idOfEmission": 3,
        "idOfMovie": 3,
        "dateOfEmission": "01-03-2015-13:30",
        "idOfHall":  1
    }
]

-> movies.xml

-->movies.xml

    <mov:movies
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:mov='urn:x-test'
    xsi:schemaLocation='urn:x-test movie.xsd'>

    <mov:movie idOfMovie="1">
        <mov:title>...</mov:title>
        <mov:is3D>TRUE</mov:is3D>
        <mov:yearOfProduction>2015</mov:yearOfProduction>
        <mov:ageCategory>7</mov:ageCategory>
        <mov:description>...</mov:description>
    </mov:movie>
    <mov:movie idOfMovie="2">
        <mov:title>...</mov:title>
        <mov:is3D>TRUE</mov:is3D>
        <mov:yearOfProduction>2015</mov:yearOfProduction>
        <mov:ageCategory>12</mov:ageCategory>
        <mov:description>...</mov:description>
    </mov:movie>
    <mov:movie idOfMovie="3">
        <mov:title>...</mov:title>
        <mov:is3D>FALSE</mov:is3D>
        <mov:yearOfProduction>2015</mov:yearOfProduction>
        <mov:ageCategory>12</mov:ageCategory>
        <mov:description>...</mov:description>
    </mov:movie>
</mov:movies>

-> emissions.xml

-->emissions.xml

    <emi:emissions
    xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
    xmlns:emi='urn:x-test'
    xsi:schemaLocation='urn:x-test emission.xsd'>

    <emi:emission idOfEmission="1">
        <emi:idOfMovie>1</emi:idOfMovie>
        <emi:dateOfEmission>01-03-2015-14:00</emi:dateOfEmission>
        <emi:idOfHall>2</emi:idOfHall>
    </emi:emission>
    <emi:emission idOfEmission="2">
        <emi:idOfMovie>1</emi:idOfMovie>
        <emi:dateOfEmission>02-03-2015-14:00</emi:dateOfEmission>
        <emi:idOfHall>2</emi:idOfHall>
    </emi:emission>
    <emi:emission idOfEmission="3">
        <emi:idOfMovie>3</emi:idOfMovie>
        <emi:dateOfEmission>01-03-2015-13:30</emi:dateOfEmission>
        <emi:idOfHall>1</emi:idOfHall>
    </emi:emission>
</emi:emissions>

我从老师那里听说,与数据相关的模式和文件类型正确地与电影"和排放"相关,与UML图不同,但是我不知道如何修复它,我认为还可以.

I heard from my teacher that into schemas and files with data, types Movie and Emission arent related properly, different than in UML diagram, but I dont know how to repair this, I thought that it is OK.

推荐答案

在发布的图像中,电影"和发射"功能中都具有idOfMovie:int属性.您可能想使用此密钥链接它们?实际上,这是在(关系)数据库世界中进行链接的方式.通过公用键链接两个表的位置.您已经设计了功能,就好像它们是数据库表一样.

In the image you posted, you have the idOfMovie:int attribute in both Movie and Emission feature. You probably wanted to use this key to link them? This is actually the way linking is done in the (relational) database world. Where you link two tables by a common key. You have designed your features as if they were db tables.

在要映射到XML的UML中,为关联命名并删除ID.映射到XML,您将得到如下信息:

In UML that you want to map to XML, give the association a name and drop the ids. Mapped to XML you get something like this:

<Movie>
  <title> 
    ..
  </title>
  <..>
  </..>
  <Emission>
    <date> .. </..>
    <hall> .. </..>
  <Emission>
  <Emission>
    <date></..>
    <hall></..>
  <Emission>

</Movie>

对于两个功能,您也可以只使用一个XSD

You can also just use a single XSD for both features

这篇关于将UML转换为JSON模式和XSD的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆