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

WARNING: Namespace thread virus (new variant?)

  • To: xml-dev@l...
  • Subject: WARNING: Namespace thread virus (new variant?)
  • From: Jeff Lowery <Jeff.Lowery@c...>
  • Date: Mon, 2 Feb 2004 10:33:20 -0800

namespace thread
I'm working with someone else's XML serialization/deserialization code and
one of the requirements of  this particular implementation is that all
serializable classes need set methods that take string  parameters (so the
XML reader can know what method to call for setting attribute values without
having the proper parameter type). In some cases, you wind up with two
similar set methods:

void setFoo( double p) 
{
   m_p = p;
}

void setFoo( String p )
{
   m_p = Double.parseDouble(p);
}

Well, this is too much bookkeeping for me. Although I could've written a
schema for the XML data file and changed the reader to validate against it,
I was in a quick and dirty mood so I just prefixed the attribute names with
type information:

<qux d_foo="3.1416"/>

Where "d_" is XMLish hungarian for "this is a double". All very naughty of
me, I'm sure, since now I have to parse the attribute name for type
information. 

Now, I'm thinking that while I'm at it I might as well do something for the
elements that map to classes:

<qux d_foo="3.1416" classType="mycompany.product.qux"/>

All the original type information is now encoded in the XML so that a
separate element-to-type map doesn't need to be created.  Java reflection
gets me the rest of the way with just few lines of code (speed is obviously
not of the essence). 

This has all been done a thousand times before in a thousand other places,
and it's of questionable practice and all that; but frankly, my dear, I
don't give damn: given the remedies, one could learn to prefer the disease. 

While this is all lazy enough for me so far, it occurred to me I could take
it one step further by using namespace declartions to encode type
information:

<qux:qux d:foo="3.1416"
xmlns:d="http://www.mycompany.com/java/primitives/double"
xmlns:qux="http://www.mycompany.com/product/classes/qux"/>

This particular approach I don't recall seeing before, but it seems too
obvious to be original. Maybe it's that it's just too horrible an approach
to be mentioned on a public forum by anybody with reputation to keep. While
I can think of several strikes against it, none have quite convinced me that
it's an utterly reprehensible idea. 

Before I sin against all that's holy, I ask the list:

Who thought of this first?
Was he shot for it?
Why?
Did his career recover?



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.