I want to define several non-inherited object types. I want to know whether I can use similar tags for them in XML. Some objects do not have the common tags. For example, the tag "name" below.
<?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>
Do we encounter any problems? In case of no theoretical error, can it make a "misunderstanding" in a large XML? Can it be problematic when we try to convert this XML to formats like SQL, Excel, Access, MongoDB etc?
Using a same-named element (such as your
nameexample) as a child of two different parent elements such aspersonandcaris natural and fully supported by XML and its related standards:XSD supports it too: See Basic Concepts: The Purchase Order in the XSD primer.
XPath (and therefore XSLT) differentiates between
/stuff/person/nameversus/stuff/car/name.Etcetera.
Note that the content models of
namecould even be different for thenameof apersonvs thenameof acar. Well-formed XML allows the content models to differ for same-named elements with the same parent even, but XML schemas (such as DTD and XSD) generally do not support the definition of such elements, so such XML would generally not be able to be considered valid.See also