views:

265

answers:

1

With all of the other hidden features questions on SO, how can we forget XML?

What are the hidden features of XML, DTD and XML Schema?

+3  A: 

Entities can be used to centralize content and make maintenance easier.

One cool trick that I learned from G. Ken Holman was that entity references can also be used for easier namespace management.

An easy and robust method of maintaining URI strings is through XML general entities.

Consider the following namespaces.ent entity file declaring both an input namespace URI and a stylesheet maintenance URI:

<!--maintenance vocabularies-->
<!ENTITY ns-xyz "urn:x-crane:xyz">
<!--end of file-->

These strings can be brought into a stylesheet through a DOCTYPE declaration at the start of the stylesheet:

<!DOCTYPE xsl:stylesheet SYSTEM "namespaces.ent">
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:abc="&ns-abc;"
  xmlns:xyz="&ns-xyz;"
  exclude-result-prefixes="xyz"
  version="1.0">
...
     <xsl:element name="def" namespace="&ns-abc;">
...

By externalizing the namespace values(and other common values) to a shared file and managed as general entities, multiple XML files can share the declared entity values. Then all of the namespace declarations in all of the XML files referencing those entities can be updated with a single update to the one file, rather than find/replace the namespace string value in each and every XML file.

This can make maintenance operations faster, easier, and more reliable for large libraries of XML and XSL files.

Mads Hansen
This is pretty interesting, but in my experience the ability to change namespaces is a problem that I've never needed to solve. Are there environments in which namespaces aren't static?
Robert Rossney
The particular XML vocabulary referenced in the case study that we dealt with did version their URIs. I know that some people version their namespace URIs for SOAP services to differentiate schema changes. That way the stub and skeleton generation code will be in different (java/.NET) packages.
Mads Hansen