XML namespace nightmares (again!)

I’ve been through
this already, and for sure most of you have too, but I fell in the trap
again today, so I’ll blog it to my perpetual abomination.



Here we go: “foo.xml” is


<foo xmlns=”something”>
<cinclude:include src=”bar.xml” xmlns:cinclude=”http://apache.org/cocoon/cinclude/1.0/>
</foo>



and “bar.xml” as


<bar/>



run this through:


<map:match pattern=”foo”>
<map:generate src=”foo.xml”/>
<map:transform type=”cinclude/>
<map:transform type=”log”/>
<map:serialize type=”xml”/>
</map:match>



Watch your console and notice how sweet is your parser in stating (correctly), that <bar/> doesn’t belong to any namespace.



Watch your browser output:


<foo xmlns=”something”>
<bar/>
</foo>



Imagine such output serialized and reparsed at a later time.



Start cursing.



Make a note to self: stay away from non fully namespaced XML whenever possible and avoid messing up with documents in the default namespace like the plague.



While at it, also note how Linotype sucks in writing code-oriented blogs and find some time to solve that.

Comments

comments

1 thought on “XML namespace nightmares (again!)”

Comments are closed.