This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Blob in attribute Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Blob in attribute" Watch "Blob in attribute" New topic

Blob in attribute

Kartik Shah
Ranch Hand

Joined: Dec 07, 2000
Posts: 102
Is it valid to have BLOB as attribute

where image contains blob data
Is it good design ?
Thanks and Regards

Kartik Shah
SCJP, SCDJWS, IBM Certified Websphere & XML, PMP & Six Sigma -
Nathaniel Stoddard
Ranch Hand

Joined: May 29, 2003
Posts: 1258
The hair on the back of my neck stood up when I read your post. I can't really tell you why, but I don't like what you're doing. Apparently there's been a long debate on what should be an attribute and what should be an element. It's possible that your image data won't be XML-compliant; since you can't smack a CDATA in an attribute, it'd be nice if you could put it in an element.
I'm still reeling from your "blob" comment--which of course is a SQL term, not an XML term.

Kartik Shah
Ranch Hand

Joined: Dec 07, 2000
Posts: 102
Thanks for your reply.
To give you an insight
We have to design and xml schema for XForm based tool.
1. Data will be entered in this tool(MS Infopath or similar) and save as XML. This may contain photograph of facilities.
2. XML will be uploaded/emailed.
3. Engine needs to put data back to relational database.
4. similarly we might need to construct xml to send already entered data to be viewed in form.
As it is easier for DOM parser to read information from attributes.
but again I am trying to find out are their any problems in doing that.
My thought is that either everything is attribute or everything is element for all table that we got in database.
-- Kartik
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Go for "everything is an element" -- that's way more safe than the other option...

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Kartik Shah
Ranch Hand

Joined: Dec 07, 2000
Posts: 102
Thanks for your reply, Lasse.
Yes. I think so everything is element is safer criteria. Do you have any specific criteria's why is it more safer ?
I am searching net to find out what is specific decision criteria for this.
One of them certainly is blob may be incompatible with attributes as point by Nathaniel.
So far I have collected following criteria we need to evaluate with regards to application that is being designed.
  • Is xml you are designing is human readable or machine readable ? Use elements if human readable

  • Use attributes if attribute readable
  • Is the data flat or hierarchical ?

  • Attributes can only hold a single level of data
    Elements on the other hand can have much more complex content models of theif own
  • Do we need to order child information item
  • Is it easier to transform a xml containing attributes or xml containing elements

  • Lasse Koskela

    Joined: Jan 23, 2002
    Posts: 11962
    Originally posted by Kartik Shah:
    Do you have any specific criteria's why is it more safer ?

    1) You're prepared for moving from a flat structure to a hierarchy
    2) You're able to use CDATA
    2) (I admit this one is a bit flaky) You don't need to worry about some parser implementation assuming a given maximum size for an attribute
    j David

    Joined: Jul 27, 2005
    Posts: 3
    InfoJet Service is a Java class library to publish InfoPath Forms to the web. InfoJet Service can be deployed as Web Services. J2EE and .Net web application with integration of InfoJet Service support the users to edit InfoPath Forms in Internet Explorer and FireFox.

    William Brogden
    Author and all-around good cowpoke

    Joined: Mar 22, 2000
    Posts: 13027
    If you really mean a BLOB, base64 encoding is the only safe way to include binary data in an XML document.
    If "Large", a very large attribute may screw up XML parsers since a parser attempts to assemble all of the startElement data at once.
    Much safer to make a large run of text as Element content.
    I agree. Here's the link:
    subject: Blob in attribute
    It's not a secret anymore!