1

This is a sample xml I am trying to create and could not find any documentation on root tag. But every xml document should have a root tag is all I know.

  <payroll  month="JAN2021">  
      <emp ID="123">
         <name>xyz</name>
         <age>50</age>
      </emp>
    </payroll>
teknik
  • 153
  • 9

1 Answers1

1

We can say that your XML is well-formed: It follows the syntactical rules for being XML.

You are right that every XML document must have a root element. In fact, it must have exactly one root element. This is one of the rules for an XML document to be well-formed.

The root element, like all elements in XML, may have attributes.

There is an additional level of rules that may be specified by a schema (such as XSD, DTD, Relax NG, etc): These user-defined rules specify a vocabulary and grammar for the elements and attributes, how these components may be arranged, and what their values may be. These rules define whether an XML document is valid.

In summary regarding your example:

  1. It is well-formed XML.
  2. It may be valid XML. We would have to associate a schema with it to be able to say.
  3. Without a schema, any attributes could be added to any element.
  4. With a schema, the names, values, and placement of attributes would be limited to constraints specified in the schema.

See also: Is there any difference between 'valid xml' and 'well formed xml'?

kjhughes
  • 106,133
  • 27
  • 181
  • 240