The ncdump utility can output NcML for classic netCDF data. The experimental ncgen4 utility can output NcML for CDL representing netCDF-4 data.
Example:
$ ncdump -x mslp.nc
<?xml version="1.0" encoding="UTF-8"?> <netcdf xmlns="http://www.unidata.ucar.edu/namespaces/netcdf/ncml-2.2" location="mslp.nc"> <dimension name="lat" length="6" /> <dimension name="lon" length="4" /> <dimension name="time" length="2" isUnlimited="true" /> <attribute name="title" value="example for workshop" /> <variable name="lat" shape="lat" type="float"> <attribute name="units" value="degrees_north" /> </variable> <variable name="lon" shape="lon" type="float"> <attribute name="units" value="degrees_east" /> </variable> <variable name="time" shape="time" type="double"> <attribute name="units" value="seconds since 2009-01-01" /> </variable> <variable name="pr" shape="time lat lon" type="float"> <attribute name="standard_name" value="air_pressure_at_sea_level" /> <attribute name="units" value="hPa" /> </variable> </netcdf>
You can also use the netCDF-Java ToolsUI utility for conversion among NcML, netCDF, and CDL, as well as other formats.