views:

163

answers:

3

I now develop websites and XML interfaces since 7 years, and never, ever came in a situation, where it was really necessary to use the &gt; for a >. All disambiguition could so far be handled by quoting <, &, " and ' alone.

Has anyone ever been in a situation (related to, e.g., SGML processing, browser issues, XSLT, ...) where you found it indespensable to escape the greater-than sign with &gt;?

Update: I just checked with the XML spec, where it says, for example, about character data in section 2.4:

Character Data

[14]      CharData       ::=      [^<&]* - ([^<&]* ']]>' [^<&]*)

So even there, the > isn't mentioned as something special, except from the ending sequence of a CDATA section.

This one single case, where the > is of any significance, would be the ending of a CDATA section, ]]>, but then again, if you'd quote it, the quote (i.e., the literal string ]]&gt;) would land literally in the output (since it's CDATA).

+7  A: 

You don't need to absolutely because almost any XML interpreter will understand what you mean. But still you use a special character without any protection if you do so.

XML is all about semantic, and this is not really semantic compliant.

About your update, you forgot this part :

The right angle bracket (>) may be represented using the string " > ", and must, for compatibility, be escaped using either " &gt; " or a character reference when it appears in the string " ]]> " in content, when that string is not marking the end of a CDATA section.

The use case given in the documentation is more about something like this :

<xmlmarkup>
]]>
</xmlmarkup>

Here the ]]> part could be a problem with old SGML parsers, so it must be escaped into = ]]&gt; for compatibilities reasons.

Colin Hebert
What about the *almost* part? Are there any that get a hickup from an unquoted `>`?
Boldewyn
Well, if anyone wrote a XML Parser that only respect the XML standards, it might happen. I don't know a parser which could have this behavior, but it wouldn't be its fault nor a problem.
Colin Hebert
An XML parser that respects the XML standards MUST accept unquoted `>`.I think the paragraph you quoted refers to compatibility with non-compliant parsers or maybe with an older (draft) version of the spec.
Daniel
@Daniel from this spec : http://www.w3.org/TR/xml/, and yes it's about compatibility. The must part means for me that I don't really have a choice here.
Colin Hebert
OK, again: The only place in the spec, where I found the `>` to have any relevance is the `]]>` CDATA closing. And that's kind of a special case, because there `]]>` won't bring you anything. (That's by the way the only section *over all*, that contains the string `>`)
Boldewyn
@Colin HEBERT: I wrote the last comment while you changed the answer (for the other readers: I, too, merged updates 1 and 2 in the question).
Boldewyn
@Downvoter, any explanation ?
Colin Hebert
+3  A: 

Not so much as an author of (x)html documents, but more as a user of sloppy written comments fields in websites, that "offer" you to insert html.

I mean if you do your site the right way, you wouldn't hardcode your content anyway, right? So your call to htmlentities or whatever (long time no see, php) would take care of replacing special characters for you. So sure, you wouldn't manually type &gt; but I hope you take measures so > is automatically replaced.

bitmask
+2  A: 

I used one not 19 hours ago to pass a strict xml validator. Another case is when you use them actually in html/xml content text (rather than attributes), like this: <.

Sure, a lax parser will accept most anything you throw at it, but if you're ever worried about XSS, &lt; is your friend.

Update: Here's an example where you need to escape > in Firefox:

<?xml version="1.0" encoding="utf-8" ?>
<test>
    ]]>
</test>

Granted, it still isn't an example of having to escape a lone >.

Douglas
Actually, would your referenced example have worked, too, if you *only* escaped the `<`? That exactly is my case. And if not, is the parser wrong, or have I missed the spot in the XML spec? http://w3.org/TR/xml/#NT-AttValue
Boldewyn
OK, now I see the point you're trying to get at. Updated the post with an example which gives paring errors in Firefox, but would parse if you never needed to escape >.
Douglas
Yep, now we're thinking the same. Colin and me found that one, too. It seems that, at least in the "XML part of SGML"-world, this is the only relevant example where `>` makes sense.
Boldewyn