My Favorite Way

Category: XML Questions    |    2 views    |    Add a Comment

 like to store data in child elements.
The following three XML documents contain exactly the same information:A date attribute is used in the first example:

< note date=”12/11/99″ >
< to > Tove < /to > < from > Jani < / from >
< heading > Reminder < /heading >
< body > Don’t forget me this weekend! < /body >
< / note >

A date element is used in the second example:

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

An expanded date element is used in the third: (THIS IS MY FAVORITE):

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

Share/Save/Bookmark

 

Avoid using attributes?

Category: XML Questions    |    1 views    |    Add a Comment

you avoid using attributes?
Here are some of the problems using attributes:

  • attributes cannot contain multiple values (child elements can)
  • attributes are not easily expandable (for future changes)
  • attributes cannot describe structures (child elements can)
  • attributes are more difficult to manipulate by program code
  • attribute values are not easy to test against a DTD

If you use attributes as containers for data, you end up with documents that are difficult to read and maintain. Try to use elements to describe data. Use attributes only to provide information that is not relevant to the data.Don’t end up like this ( if you think this looks
like XML,you have not understood the point):

< note day=”12″ month=”11″ year=”99″to=”Tove” from=”Jani” heading=”Reminder” Body=”Don’t forget me this weekend!” >
< /note >

Share/Save/Bookmark

 

An Exception to my Attribute rule

Category: XML Questions    |    3 views    |    Add a Comment

Rules always have exceptions.
My rule about attributes has one exception:
Sometimes I assign ID references to elements. These ID references can be used to access XML elements in much the same way as the NAME or ID attributes in HTML.

This example demonstrates this:

< messages >
< note id=”p501″ > < to > Tove < /to > < from > Jani < /from >
< heading > Reminder < /heading >
< body > Don’t forget me this weekend! < /body >
< /note >
< note id=”p502″ > < to > Jani < /to > < from > Tove < /from >
< heading > Re: Reminder < /heading >
< body > I will not! < /body >
< /note >
< /messages >

XML VALIDATION

XML with correct syntax is Well Formed XML.
XML validated against a DTD is Valid XML.

Share/Save/Bookmark

 

“Well Formed” XML documents

Category: XML Questions    |    0 views    |    Add a Comment

 “Well Formed” XML document has correct XML syntax.
A “Well Formed” XML document is a document that conforms to the XML< ?xml version=”1.0″ encoding=”ISO-8859-1″? >
< note >
< to > Tove < /to >
< from > Jani < /from >
< heading > Reminder < /heading >
< body > Don’t forget me this weekend! < /body >
< /note >

Share/Save/Bookmark