Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

You can't process XML that uses namespaces without a namespace declaration. A namespace prefix is just a shorthand for the namespace itself.

prefix:name-of-element doesn't mean anything by itself, you need to know what 'prefix' stands for.

As it is, this XML is not parsable; it's not well-formed and therefore it shouldn't even be called XML; it's just text with random tags thrown in.

It is, indeed, quite shocking.



Maybe it's just me, and it's probably wrong, but more than once I pre-processed XML data by replacing all the "namespace:tag" by "namespace-tag" so that I can easily parse the XML without having to care about namespaces. I've never been convinced that this feature has much use anyway.


You never understood what they were actually for, then. The namespace will have a schema, and the schema can be used to validate the elements of that namespace. Not used in a "just import the data!" scenario, sure, but a lot of people who use XML do care about that kind of validation.


> The namespace will have a schema, and the schema can be used to validate the elements of that namespace.

That's one option. But a Schema (or DTD) is not mandatory, and not all schemas can easily be linked (few tools handle relaxng or schematron for namespace spec).

The core purpose of XML namespaces, and that of any namespace really, is better modularity and compositionability by preventing name collisions. This is useful when manipulating XML via XML (e.g. XSL, Genshi, ...) or when using multiple XML dialects in the same file (either because they're orthogonal or because they complement one another) for instance. You could do it by explicit prefixing à la C or Objective-C, but it tends to get dreary, requires everybody's cooperation and generally looks bad (not that xml namespaces look overly sexy).


Technically you "can" if you manage to find a non-namespace-aware XML parser, it'll parse `prefix:name` as the ELEMENTNAME `prefix:name`.

> As it is, this XML is not parsable

It's parsable with a non-namespace-aware XML parser (ignoring tagsoup parsers as we're pretenting this is supposed to be an XML document)


That's true; but where would you find such a beast? AFAIK you can't switch namespace-awareness off in modern parsers, so you'd have to find a very (very) old version...


> AFAIK you can't switch namespace-awareness off in modern parsers

Apparently, the JDK's javax.xml.parsers.*Factory can return namespace-unaware parsers and — even stranger — do so by default:

http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/D...

> Specifies that the parser produced by this code will provide support for XML namespaces. By default the value of this is set to false

http://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/S...

> Specifies that the parser produced by this code will provide support for XML namespaces. By default the value of this is set to false.

Whether they qualify as "modern parsers" can be debated and I didn't test their behavior, but there you are.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: