Case conventions on element names?

前端 未结 10 1743
予麋鹿
予麋鹿 2020-12-02 18:00

Are there any formal recommendations on element casing in XML?

I know XHTML uses lowercase element names (as opposed to HTML which canonically uses uppercas

10条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-02 18:38

    To expand on my comment above: the use of 'lowercase with hyphens' has some problems in XSLT. Specifically it is easy to confuse a node called, say, 'year-from-age' with a formula 'year - age' (e.g. subtract age from year).

    As @KarlKieninger points out, this is only a problem at the human level and not for the XSLT parser. However since this will often not produce an error, using 'lowercase with hyphens' as a standard is asking for trouble, IMHO.

    Some pertinent examples:

    11
    
    outputs 2, as expected
    
    11
    
    DOES NOT ERROR, BUT OUTPUTS NOTHING AT ALL
    

    In the above code, you must put at least one space before a subtraction operator, but there is no such requirement for an addition operator.

    11
    
    outputs 0, as expected
    

    But note how confusing the above is to read!

    132
    
    outputs 3
    
    132
    
    outputs -1
    

    The presence of a single space changes the output above, but neither variant is an error.

提交回复
热议问题