File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes using attributes or elements??? 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 "using attributes or elements???" Watch "using attributes or elements???" New topic

using attributes or elements???

Yell Srik
Ranch Hand

Joined: Mar 10, 2004
Posts: 61
i have a doubt in XML. using HTML/Java script forms, i have created a graphical interface using which the user is allowed to choose jpeg images(maps), text files etc; ie from a set of jpeg images, text files etc, the user can choose any one. i am planning to use XML for data exchange. i plan to develop a XML file that contains the user's choices. a JSP page on the server end interprets this XML file and extracts the data.
how can i represent the files in as XML tags:
is this representation right:
(1) <userselection id1="D:\mydocuments\us.jpg"> USA </userselection>
(2) <userselection>
<map id="1">D:\Webmapping\kerala\keralabw.jpg</map>
in (1), i plan to include all the images and text files as attributes whereas in (2), these are stored as elements.
can u suggest which of the two representations is better or is there a better way of using XML?
thanks in advance.
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
I'd go for (2)

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

Joined: Dec 07, 2000
Posts: 102
Any specific reason to go for option 2 in this case ?
This seems to part of bigger debate that is going on...
When is an attribute attribute ?
Elements or attributes ?

XML Syntax Recommendation for Serializing Graphs of Data

Kartik Shah
SCJP, SCDJWS, IBM Certified Websphere & XML, PMP & Six Sigma -
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
Using "id1" as the attribute name implies that there will be id2, id3, id4, etc. which would be horrible for the obvious reasons -- one of them being that it's practically impossible to describe this with DTD or XSD.
I agree. Here's the link:
subject: using attributes or elements???
It's not a secret anymore!