There Are Days When I Hate XML

…and days when I really hate XML.

In this case, I have an XML document like

<?xml version="1.0" ?>
<foo xmlns="">
  <thing id="first"/>
  <thing id="second"/>
  <thing id="third"/>

and I want to get things out of it with XPath.

But I couldn’t manage to select things exactly, such as the <foo> element at the top. You’d think “/foo” would do it, but it didn’t.

Eventually I found out that the problem is the xmlns=”...” attribute. It looks perfectly normal, saying that if you have <thing> without a prefix (like “<ns:thing>”), then it’s in the “” namespace.

However, in XPath, if you specify “ns:thing”, it means “a thing element in whichever namespace the ns prefix corresponds to”. BUT “thing” means “a thing element that’s not in a namespace”.

So how do you specify an element that’s the empty-string namespace, as above? The obvious way would be to select “:thing”, but that doesn’t work. Too simple, I suppose. Maybe that gets confused with CSS pseudo-selectors or something.

No, apparently the thing you need to do is to invent a prefix for the standard elements of the file you’re parsing. That is, add “ns” as another prefix that maps onto “” and then select “ns:thing”. There are different ways of doing this, depending which library you’re using to make XPath queries, but still, it seems like a giant pain in the ass.

Respecting Everyone’s Beliefs

There’s a phrase that’s been annoying me lately. I don’t know whether it’s a new thing, or something that’s been floating around for years but only recently came to my attention, but it’s been bugging me.

“We should respect everyone’s ideas.”

This is exactly wrong. There are plenty of ideas out there that don’t deserve respect: the idea that women shouldn’t be allowed to vote, that the ACLU hates America, that the Earth is flat, that good deeds are pointless unless you also believe in a Jewish zombie, that farts should be used as currency, and many more.

Respecting people, now that’s something else entirely. Everyone is entitled to certain rights, simply by virtue of being human. People can lose those rights, like a criminal who goes to prison and loses his rght to go where he likes, but every person starts out with a core set of rights. A more pedestrian example is that I tend to start out believing that you are a basically decent, honest person until you demonstrate otherwise.

But ideas are not people. They don’t suffer when they’re abandoned or overturned. They don’t feel shame when they’re shown to be idiotic, nor do they get lonely when held only by a handful of loons. Eliminating an idea is nothing like killing a person.

Of course, the problem is that many ideas, particularly religious or ideological ones, are tightly wrapped up in people’s sense of identity or self-worth; so saying that someone has a stupid idea or holds a stupid belief feels to them as if they’re being told that they themselves are stupid.

And so “all ideas should be respected” is really cover for “don’t criticize my religion”. The reasoning seems to be, “We both hold ideas that we’re not willing to abandon, even though we realize that they can’t stand up to critical examination. So I’ll agree not to shoot down your weak ideas if you’ll agree not to attack mine.” This seems to be the truce entered into in civilized countries where religions and other ideologies aren’t allowed to impose themselves through force of arms anymore.

But of course it all depends on all participants having weak beliefs that they want to protect. Along come skeptics who don’t want to hold weak beliefs, who want people to point out their false beliefs so they can get rid of them, and upset this unstable balance.

So fuck beliefs. They don’t automatically deserve my respect.

Now, I have friends (of the “I’d help them move a corpse, and vice-versa” variety) who hold wacky beliefs. (Mostly religious ones, as you might expect.) And yes, there are topics that, by mostly-unspoken agreement, we venture into only rarely. But that’s because I don’t want to upset my friends (see “sense of identity and self-worth”, above). In other words, it’s about respecting the person, not the belief.