5 ms·
He has a few valid complaints (by a few I mean one), but this is really not that bad compared to a lot of the XML floating around. No reason to be shocked "The
by gizzlon 14y ago
He has a few valid complaints (by a few I mean one), but this is really not that bad compared to a lot of the XML floating around. No reason to be shocked
"There are no namespace declarations. No self-respecting XML parser will have anything to do with this XML data."
I don't get this comment. I have never seen an XML parser that would refuse to parse XML without a namespace..
Am i missing something? Or is that just mindless hyperbole?
- masklinn 14y ago> Am i missing something? Or is that just mindless hyperbole? Note that the document uses namespaces but does not declare them. In Python, both ElementTree and LXML will blow up parsing when they encounter the first undeclared prefix (dc, from dc:creator)
- gizzlon 14y agoAh, you're right, I did miss something =) Still nothing to be "shocked" about though ..
- masklinn 14y agoTFA wasn't "shocked" (I suspect he was being slightly hyperbolic) at the sole invalidity-through-broken-namespacing, broken templating also had a hand in it: simply exporting a post and proof-reading the output is sufficient to catch the latter. Then again, you just have to put the output through any XML parser (it's not hard to find) to realize the document is completely broken, but...
- bambax 14y agoYou 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.
- masklinn 14y agoTechnically 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)
- bambax 14y agoThat'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...
- masklinn 14y ago> 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/DocumentBuilderFactory.html#setNamespaceAware(boolean) 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/SAXParserFactory.html#setNamespaceAware(boolean) 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.
- laurent123456 14y agoMaybe 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.
- nullymcnull 14y ago
- obviouslygreen 14y ago"Worse things have happened" is a very tempting and unfortunate dismissal... I think we all do it, but when something is broken, is it really that important what else has been broken that may have been worse? Yes, shit happens, and it's never going to stop happening. Not in the face of all the misguided idealism in the world. But is being punched in the face OK because the puncher didn't use brass knuckles? If he did, is it still OK, because people have been shot in the face, and that's a lot worse than being punched? Anyway, I thought the same about namespacing until that was addressed in a more constructive reply. So thanks for asking that question. :)