Is there any difference between an empty simple element and an empty complex element in a xml file? How can I distinguish them?
On w3schools I found:
<element></element>
or <element />
; in addition it says that "Empty elements can have attributes.".<product pid="1345"/>
Being simple or complex is a property of a type, not (directly) of an element. We can say that an element conforms to a type (specifically, a type defined in an XSD Schema), and we can say that the type is simple or complex, but the categories of simple and complex types are overlapping in the kinds of elements that they allow. Specifically, both complex types and simple types might allow empty elements such as <e/>
, and elements with text content such as <e>foo</e>
. If we see an element that has attributes, or child elements, then we know that it can't conform to any simple type, but if it has neither, then we don't know without looking at the schema.
The answer to your question "how can I distinguish them" is that you need to look in the schema; you can't distinguish them just from the instance alone.