Inline XML

by Lachlan Cannon

24 Reader Comments

Back to the Article
  1. Hopefully those readers who were initially unhappy can now focus on the article’s subject. :)

    Copy & paste the code below to embed this comment.
  2. I was surprised but the example didn’t work in Mozilla (1.2b) for me. The CSS color coding was missing. Also the DOCTYPE declaration should be removed as it doesn’t conform to XHTML 1.1. And lastly, the document should have been served with text/xml, application/xml, application/xhtml+xml, not text/html.

    Copy & paste the code below to embed this comment.
  3. *And lastly, the document should have been served with text/xml, application/xml, or application/xhtml+xml, not text/html.

    Copy & paste the code below to embed this comment.
  4. I agree with Lach’s last point about namespaced elements being more appropriate vehicles for semantic meaning than class attributes; and the article highlights (X)HTML’s shotgun approach to semantic markup.

    I’ve done several academic publishing projects in HTML and been infuriated by the hit-and-miss approach of the default semantic elements: (X)HTML has <var>, <kbd>, <code> and <samp> so obviously someone went overboard on programming semantics, but there’s not a single element to mark up an author’s name or the title of a publication. There’s <cite> of course, but that’s only really appropriate when you’re actually citing a source. Hence I have to fill my markup with <em class=“author”> and <em class=“title”>. Obviously this isn’t an editorial playground, but it’s something that’s bugged me since day one ;)

    Also, I believe IE as of version 5 or so has allowed you to apply style to unknown tags, just as Mozilla has, so the browser should work with custom tags with or without proper namespacing.

    Copy & paste the code below to embed this comment.
  5. Go back to ‘class’.

    As others have pointed out, using the ‘class’ attribute to specify semantic details is not only just fine, but expected. Think of the ‘class’ attribute as more of a “subclass” attribute – in that it allows you to “subclass” a particular element and provide a more specific instance thereof. In the case of <span> and <div>, since they are the most generic of tags, subclassing them results in an element that is semantically richer, but not much (if any) richer than any other semantic specific element (like ) without a class attribute. <div class=“function”> is semantically close enough to <function> to be just fine for now (until 95% of folks are using browsers with sufficient native XML support (parsing, selectors, dom, schema etc.)).
    Until then, if you must use your own XML tags, consider transforming them server side to span/div tags with the appropriate class before sending them to the client.


    Would Namespaces by any other name smell so foul?

    Namespaces are bugly. They are perhaps the worst aesthetic corruption of markup to come out of W3C. Ick. They have enabled such ugliness as XLink, which has polluted the latest document formats (like SVG – explain to me again why SVG needed a different <a> element instead of simply reusing what was in XHTML?).


    Modern selectors

    The “\:” syntax was an experimental way to specify namespaces in CSS selectors that has since been abandoned. Go here:

    http://www.w3.org/TR/css3-selectors/#typenmsp

    For the right way to use selectors with namespaces (if you must).


    Tyler

    Copy & paste the code below to embed this comment.
  6. Tyler, if you read the comments which are posted here I did say that for now using classes is no doubt the better method. Hopefully sufficient browser support is not too far up the track, and by that time people will be ready to use namespaces.

    Secondly, I don’t think namespaces are ugly at all. The syntax works just right for how they should work, but if you have a problem with it, you should take it up on a W3C mailing list.

    Thirdly, not all languages could re-use xhtml semantics. Browsers can’t just assume that because an element has the same name it’ll mean the same thing, or xml would be pointless, you might as well just add tags to xhtml. Therefore, more generic technologies need to be developed for xml, to be able to apply for all xml languages if necessary.

    Lastly, thankyou for the updated selector link. Do you know how support for that compares with support for the droped “\:”?

    Copy & paste the code below to embed this comment.
  7. \: is a valid way to match elements “based on their fully qualified name”.

    See: http://www.w3.org/TR/css3-selectors/#downlevel

    Copy & paste the code below to embed this comment.
  8. Funny thing is that I was just finishing up a page of demo code for my new Web site. I’d been using classes to colour code them. Nice idea, but I like validating my docs plus I don’t think ditching Opera users is ok. Maybe Netscape/Internet Explorer 4 users, but not above that mark. In future I will use inline XML to colour code my work, but for now I’ll use what I know works.

    Thanks, short but sweet article. =)

    Copy & paste the code below to embed this comment.
  9. In the caveat it talks about how mix-name-spaced documents don’t validate against a DTD, unless there is a DTD specifically for that collection fo mix-name-spaces (e.g. XHTML+MathML and XHTML+SVG+MathML).

    I know that this is becuase DTD’s arent name space aware.
    My question is, if we ever get to the point of using some other validation technology/language (such as xml Schema or relax ng, etc (now please don’t start a flame war about xml schema. I’m only using it as an example of “some other form of validation” – I’ll just generically call them all SuperSchema), will we be able to validate a specific namespace from a mixed namespace document. For instance, say I have xhtml + mynamespace, could I validate it against the SuperSchema for “xhtml” and it will say “As fas as the xhtml in this document is concerned, it validates. The other namespace is up to you.” I could then validate it against a SuperSchema for mynames space. In other words I could validate my document against a SuperSchema for each langauge contained in the mix, and none of them would blow-up becuase of the other namespaces.

    Also – Thanks for this article. It is very helpful.

    Copy & paste the code below to embed this comment.
  10. Just a heads up. Peter Janes has helped to rework my example using the @namepsace selector method. It’s available at: http://illuminosity.net/writing/articles/inlinexml/at-namespace.html .

    Jeff, I would hope that this is where we are heading. One day I would like to be able to write up my document using mixed and matched vocabularies, tell my editor to validate, and it would validate against the main schema, saying that yes it’s fine for these documents from other vocabularies to be used at these points, and the fragments from all the different vocabularies validate against their own vocabulary schema. I’m not aware of whether or not there are any schema languages which can do this yet, but there are a few efforts going into producing different schemae, and hopefully they will gravitate towards working that way.

    Copy & paste the code below to embed this comment.
  11. what is the use of putting inlinefigure element in an XML document. once after putting the inlinefigure if i want to see the figure then what i have to do. please help me.

    Copy & paste the code below to embed this comment.
  12. what is the use of putting inlinefigure element in an XML document. once after putting the inlinefigure if i want to see the figure then what i have to do. please help me.

    Copy & paste the code below to embed this comment.
  13. as for color coding you can’t yet beat [removed]
    http://www.byteshift.de/tips/css/get-rid-of-h1-formatting
    (this demo is on a different subject, but uses JS for adding colors)

    Copy & paste the code below to embed this comment.
  14. What about browsers compatibility?

    Copy & paste the code below to embed this comment.