working with XML


These are some things I have learned along the way about working with XML.

XML documents begin with <?xml version="1.0" encoding="iso-8859-1"?> on its own line. you can also use utf-8 encoding. in fact, sometimes it is required.

You can't just put straignt & into the attribute of an element. it must be &#38; instead. for instance, <li href="" title="blog"></li> will not validate. it should instead be written <li href=";def=456" title="blog"></li>

There may be a some, none, or a lot of use of CDATA, but I think you mostly see that during parsing. It is not very often you see it in the XML document itself.

There are what is called singletons. if you have seen XHTML meta, img, input, br elements/tags, they are in the same format: <br /> <input type="text" readonly="true" disabled="false" name="zip" /> you will notice that the readonly attribute isn't simply the word "readonly" by itself - that's not allowed. you will also notice that with the br tag/element and the input tag/element that they both end with a space and a / before the closing >. this only applies to singletons - tags that don't have a closing tag.

with XML you can name your tags/elements anything you want. <greeting date="2/2/2008">Hello</greeting>

As with XHTML, XML must be properly nested. <b><i></b></i> is not allowed. use <b><i></i></b> instead.