Jump to content

Attributes or Nodes?


Brok3n

Recommended Posts

Hi everyone,I am planning a project that will interpret and synthesize output from a mark-up language similar in syntax XHTML.W3Schools XML tutorial ( http://www.w3schools.com/xml/xml_attributes.asp See 'My Favourite Way') says that I should refrain from using Attributes to hold data, yet isn't this the way XHTML does it? For example (from W3Schools, note the DATE below).

<note date="12/11/2002"><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

<note><date>12/11/2002</date><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

<note><date>  <day>12</day>  <month>11</month>  <year>2002</year></date><to>Tove</to><from>Jani</from><heading>Reminder</heading><body>Don't forget me this weekend!</body></note>

See the three ways of doing the same thing? I understand that the third and most expanded form is more easily expanded, more structured etc. BUT, if I am going to be using Attributes to hold small amounts of information (ie. properties [height, width, depth, x, y, z, colour, tooltip, events, effects, src, etc]) and then the auctual data between the tags like this:

<tag property1="x" property2="x" property3="x">DATA</tag>

Is that an 'acceptable' way of doing it?Hope I did not get confusing there. Any info is appreciated, and thankyou in advance.

Link to comment
Share on other sites

By the way, there's a forth way, which I think could suit well XSLT.

<date day="12" month="11" year="2002" />

However, note that this is not expandable. Any changes to this concept structure will cause major redesigns of the XSLT. The third way would only cause minor changes, which is why it's best.Attributes should be used when the data has no way of possibly expanding. In the case of a date, the forth format is acceptable. I mean, whenever is the day going to have something else? If you need hours, minutes, etc. you can simly add new attributes and/or change the date to "time" even. All is one change and few minor in the XSLT.Another use for attributes are functional purposes. For example

<question>Which site are you browsing now?</question><answer correct="yes">W3Schools.com</answer><answer>Microsoft.com</answer><answer>W3C.org</answer>

In this case, "correct" is an arrtibute which is not displayed on the screen, but it will be used by a server side scripting language to check if the given answer is correct.In all other cases, elements are the best way to go, scince they offer future expanding. I mean, just look at what XHTML 2.0 is expected to have. Deprecate the <img> tag, because the alt text can only be plain text (simply because it's in attribute, and attribute don't allow tags and attributes inside them). The solution instead would be to allow every element to hold an image, and it's content would be considered the alternative. The URI of an image is never going to be more then a string, so it's absolutely great to hold it in attribute. The ingenious thing here is the alternative, which unlike the URI is seen on the screen either as a tooltip(IE) or when the image is loading(FF and Opera).

Link to comment
Share on other sites

I See.I intend to use my own PHP XML parser class (similar functionality to SimpleXML), and also .NET 2005 (client software). As I have never used XLST (and for this project do not see a need, mind you, i don't really know what it does), it's not a concern if it is harder to use with XLST.The paramters stored as Attributes will only contain data that are considered 'properties' of the defined object, size, location, colour, whatever. This is going to be far better than I thought. Thankyou very much for your help.Thanks very much boen_robot, Little Goat. Much appreciated.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...