minidom self-closes empty SCRIPT tags
I panicked a bit today when I went to Automatically grab flavor text snippets in Nisus in IE 8, and then Firefox 3.6.10, and discovered that the page stopped displaying just before the code sample!
The immediate issue turned out to be that those browsers still don’t support self-closing <script> tags. Safari 5.0.2 does, and it’s valid XHTML, so I hadn’t noticed it.
However, I knew that when I made the Django template that contains this tag. It looks like this in the template file:
- <script type="text/javascript" src="{{ centralstart }}/library/scripts/code.js"></script>
And I verified that it was working on every other page I could think of that held it.
The answer turned out be that the failing page also contained a media file, and, being a lazy programmer, I don’t usually manually place each media file on a page, I just parse the XHTML, distribute the media evenly among the elements, and then reconstitute the XHTML.
Python’s minidom was—correctly, this is what should happen with empty elements—seeing that the script element had no content and self-closing it.
The solution is a further, very minor, hack: put a space between <script> and </script> so that the element does have content and can’t self-close:
- <script type="text/javascript" src="{{ centralstart }}/library/scripts/code.js"> </script>
I’d bold the new character, but it’s a space.
- Automatically distributing images within XHTML
- One of the nice things about XHTML is that the tools for reading XML have finally matured. So if, for example, I want to have a series of images automatically placed within my web page, I can parse the XHTML of the content to ensure that nothing is broken.
- Automatically grab flavor text snippets in Nisus
- In Nisus, it is very easy to grab all text of a specific style, and its nearest heading. This makes it easy to make “room description cards” for handing to the players after reading them.
More Duh
- ModelForms and FormViews
- This is just a notice because when I did a search, nothing came up. Don’t use ModelForm with FormView, use UpdateView instead.
- Django using too much memory? Turn off DEBUG=True!
- DEBUG=False can save hundreds of megabytes in Django command-line scripts, and probably in Django web processes.
- Add nodes to SimpleXMLElement
- If you want to add child nodes in PHP’s SimpleXML, the correct way to do it is to add the node first, then create it.
- No distutils? Install Xcode
- If Distutils is not available on Mac OS X Leopard, install the Xcode developer tools. Also, the upgrade process I followed for upgrading from Mailman 2.1.9 to 2.1.12.
- Django QuerySet Heisenberg gotcha
- Observing a system changes the system. That’s especially true with Django’s QuerySet API.
More XML
- Catalina: iTunes Library XML
- What does Catalina mean for 42 Astounding Scripts?
- Parsing JSKit/Echo XML using PHP
- In the comments, dpusa wants to import JSKit comments into WordPress, which uses PHP. Here’s how to parse them using PHP.
- Parsing JSKit/Echo XML comments files
- While I’m not a big fan of remote comment systems for privacy reasons, I was willing to use JSKit as a temporary solution because they provide an easy XML dump of posted comments. This weekend, I finally moved my main blog to custom comments; here’s how I parsed JSKit’s XML file.
- Auto-closing HTML tags in comments
- One of the biggest problems on blogs is that comments often get stuck with unclosed italics, bold, or links. You can automatically close them by transforming the HTML snippet into an XML document.
- A present for Palm
- Palm needs a little help understanding XML.
- Five more pages with the topic XML, and other related pages