对 XML 中的不同对象使用相似的标签

问题描述 投票:0回答:1

我想定义几种非继承的对象类型。我想知道是否可以在 XML 中为它们使用类似的标签。有些对象没有通用标签。 例如下面的标签“name”。

<?xml version="1.0" encoding="UTF-8"?>
<stuff>
    <person>
        <name>
            John
        </name>
        <age>
            30
        </age>
    </person>
    <car>
        <name>
            BMW
        </name>
        <price>
            50000
        </price>
    </car>
    <book>
        <name>
            Harry Potter
        </name>
        <author>
            Rowling
        </author>
    </book>
    <city>
        <country>
            USA
        </country>
        <population>
            5000000
        </population>
    </city>
</stuff>

我们遇到任何问题吗? 在没有理论错误的情况下,能在大的XML中造成“误解”吗? 当我们尝试将此 XML 转换为 SQL、Excel、Access、MongoDB 等格式时会出现问题吗?

xml
1个回答
0
投票

我没有发现使用上述 xml 有任何问题,您必须查询对象并为每个对象创建一个表/集合。

或者

为每个创建一个类型字段并将它们存储在同一个表/集合中

{ "type": "person", "name": "John", "age": 30 }
{ "type": "car", "name": "BMW", "price": 50000 }
{ "type": "book", "name": "Harry Potter", "author": "Rowling" }
© www.soinside.com 2019 - 2024. All rights reserved.