OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: [xml-dev] Vocabulary Combination and optional namespaces

[ Lists Home | Date Index | Thread Index ]

Paul Prescod <paul@prescod.net> wrote:

| In fact, here's what I did: I wrote a Python program that worked with 
| RSS. Then I added the "xmlns attribute" [...] rewrote the program using 
| full namespaces. The changes were straightforward and added exactly one 
| line of code (the namespace declaration).

The interesting part is not that you had to add a line of code for the ns
declaration but that you had to make changes in the body of the code,
from:

| def countTitleWords(dom):
| 	print
| 	items = dom.getElementsByTagName("item")
| 	for item in items:
| 		title = item.getElementsByTagName("title")[0]
| 		words = len(title.firstChild.nodeValue.split())
| 		newel = dom.createElement("words")
| 		newel.appendChild(dom.createTextNode(str(words)))
| 		item.appendChild(newel)
| 	print dom.toxml()

to:

| def countTitleWordsNS(dom):
| 	print
| 	items = dom.getElementsByTagNameNS(rssURI, "item")
| 	for item in items:
| 		title = item.getElementsByTagNameNS(rssURI, "title")[0]
| 		words = len(title.firstChild.nodeValue.split())
| 		newel = dom.createElementNS(rssURI, "words")
| 		newel.appendChild(dom.createTextNode(str(words)))
| 		item.appendChild(newel)
| 	print dom.toxml()

Now, picture if you will, the utility of "vocabulary specific views"
instead of colonified names.  Let's suppose the dom object supported a
method to impose such a filter to yield a subdom.  Then you could do
something like this

rssURI = "http://www/rss";

countTitleWords(minidom.parse("rss.xml").view(rssURI))

using your original code, with no need to bother with where in the
document the rss stuff was or in what form.  (That is, the dom.view() ->
dom call could have been a no-op but your original code is disengaged from
such inessentials.)

| And anyhow, it should be the responsibility of infrastructure to track 
| the namespace environment. XSLT is an example of infrastructure that 
| does a pretty good job.

But your Python code was exposed to the problem even in the simple case.
I'll grant that the changes were simple, but why did anything have to be
changed at all?





 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS