Home > Net >  Short syntax equivalent
Short syntax equivalent

Time:11-22

What's the difference between

        <Crop CropVisible="No"></Crop>

and

        <Crop CropVisible="No"/>

Are both valid?

What is the technical name for this construct?

Notepad changes the top one into the bottom one when I reformat.

CodePudding user response:

There is no difference. They are both valid. It is an empty element tag (colloquially known as a self-closing tag) as opposed to a start tag and an end tag.

CodePudding user response:

No, there's no difference in XML. It's usually called a self-closing tag (though Quentin's answer shows that the spec uses a different term). In both cases, Crop is an element with no child elements.

(The answer would be different for HTML, which looks a bit like XML but is quite different.)

CodePudding user response:

https://www.w3.org/TR/2008/REC-xml-20081126/#sec-starttags defines "Tags for Empty Elements" as:

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

Empty-element tags may be used for any element which has no content, whether or not it is declared using the keyword EMPTY. For interoperability, the empty-element tag should be used, and should only be used, for elements which are declared EMPTY.

Examples of empty elements:

<IMG align="left" src="http://www.w3.org/Icons/WWW/w3c_home" />
<br></br>
<br/>

Of course, "SHOULD" means that there may exist valid reasons in particular circumstances to ignore a particular item, but the full implications must be understood and carefully weighed before choosing a different course.

This is the only reference in "Extensible Markup Language (XML) 1.0 (Fifth Edition)" and "Extensible Markup Language (XML) 1.1 (Second Edition)" from W3C.

  • Related