Nav

XML Coding Style Guide

XML Formatting

Wrapping

Wrap lines at 120 characters. Wrap attributes only if they exceed 120 characters.

Indenting

Use four spaces for indenting, rather that tabs.

Whitespace

Empty tags should not contain whitespace.
Incorrect: <tag />
Correct: <tag/>

Aligning

Align wrapped attributes with the first attribute on the previous line.

XML Schema Conventions

Schema item

Convention

Example or Note

Simple Types and Complex Types

Use nouns for the names of simple and complex types. Use mixed case names, starting with lowercase. Always apply a Type suffix.

inboundRouterType

Attributes

Use mixed case names for attributes, starting with lowercase.

address
name
synchronous

Element

Use lowercase for element names. Use a "-" separator between words, when necessary.

inbound-router
custom-transformer

Groups

Use mixed case names for groups, starting with lowercase. Always apply a Group suffix.

inboundRouterGroup
exceptionStrategiesGroup

Namespaces

see example

http://www.mulesource.org/schema/mule/${module}/${version}

Namespace prefixes

see example

${module}

Occurrence constraint

Use occurrence constraints only when non-default values are required.

Note: For clarity’s sake, include either all values, or just the non-default values. Given the number of places where minOccurs/maxOccurs attributes exists, it is tedious to complete all values.

XML Schema Best Practices

  • Avoid restricting complex types; restricting simple types is acceptable.

  • Use elements rather than attributes in the following circumstances:

    • you require complex types 

    • you do not have a requirement to specify valid combinations (for example, with choice)

    • you must accommodate future extensibility

  • Keep schema restrictive but extensible

  • Do not use unbound choice model groups, as per the example below.


         
      
1
2
3
<choice minOccurs="0" max Occurs="unbounded">
    ...
</choice>
  • Always order elements using <sequence/> . 

  • Specify occurrence constraints only on references to groups, rather than groups.

Resources

Access xFront Best Practices for more details.