1

I had thought xml had to have a start & end tag, for example

<SalesRankings> 1 </SalesRankings>

but this is a jpg of my XML, where the above format is not followed. I pasted it into an XML validator & it didn't throw any errors, so is it valid?

<SalesRankings/>

Is the above Malformed XML or not?

har07
  • 88,338
  • 12
  • 84
  • 137
peskywinnets
  • 63
  • 3
  • 11

2 Answers2

1

Yes, it is valid (or rather, well-formed).

In the XML 1.0 specification, particularly section 3.1 Start-Tags, End-Tags, and Empty-Element Tags, this kind of element referenced as empty-element tag, which format defined formally as :

[44] EmptyElemTag ::= '<' Name (S Attribute)* S? '/>' [WFC: Unique Att Spec]

Examples of empty elements from the spec :

<IMG align="left"
 src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>
Community
  • 1
  • 1
har07
  • 88,338
  • 12
  • 84
  • 137
0

That is called a "self-closing tag" - the vast majority of xml parsers will treat that as valid, exactly equivalent to "<SalesRankings></SalesRankings>".

neminem
  • 2,658
  • 5
  • 27
  • 36