[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: RE: Namespaces Best Practice

  • From: Jonathan Borden <jborden@m...>
  • To: Tony.Coates@r..., xml-dev@l...
  • Date: Fri, 21 Sep 2001 08:38:12 -0400

best practice serialization
<Tony.Coates@r...> wrote:

> I was told that the XSLT spec is likely to tighten up to stop processors
from trying to
> put all namespace declarations at the top.  There are two reasons for
this.  One is
> for performance, as mentioned in a previous post.  The other is that
namespace
> prefixes are allowed to be re-used in different parts of a document for
different
> namespaces, and XSLT is sensitive to the prefix as well as the namespace,
so
> there is no (simple) general mechanism by which you actually can move all
> namespace declarations to the top in all possible cases.

Actually there is a simple straightforward algorithm to do this exact thing
(in the non-streaming case).

Algorithm to normalize namespace prefixes

During the parse phase phase, build a map of prefix/namespaceURI bindings.
Remove all duplicate prefix/namespaceURI bindings by only using the first
prefix declared on a namespaceURI and renaming any prefix declared on a
namespaceURI already in the map.

During the serialization phase, emit the prefix/ns bindings at xmlns
attributes of the root element. As each element/attribute is emitted, lookup
the prefix from the node's namespaceURI in the map.

In the frequent case where a document is parsed, processed and emitted, this
algorithm adds negligable overhead.

>
> Of course, you can argue that it might be poor practice to re-use
namespace prefixes in this way, but XSLT processor authors shouldn't be
asked to get into the business of only supporting those documents that they
consider exemplars of "good practice".

Programming language processors need to accept all legal forms of a language
... on the other hand people who need to debug programs, or read XML
documents, do appreciate such good practices. I suspect that if we were to
run a "delibately obfuscated XML" contest, documents employing heavy prefix
overloading and mixed use of qualified and unqualified -unprefixed- elements
would carry the day.

Jonathan



PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.