File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "using attributes or elements???" Watch "using attributes or elements???" New topic
Author

using attributes or elements???

Yell Srik
Ranch Hand

Joined: Mar 10, 2004
Posts: 61
hi,
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>
(or)
(2) <userselection>
<map id="1">D:\Webmapping\kerala\keralabw.jpg</map>
</userselection>
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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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 - http://blog.kartikshah.info
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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: http://aspose.com/file-tools
 
subject: using attributes or elements???
 
Similar Threads
how to use servlets/JSP/EJB ???
is the DOM representation right???
javascript and database
representing as XML
generating XML using servlets/jsp