Live data from Hacker News

XPath is actually pretty useful once it stops being confusing

news.rapgenius.com

71–77 of 77 posts

Re: XPath is actually pretty useful once it stops being confusing

#71
post #61

I'm happy to see many other XPath fans here. But as far as the OP, this seems like a case of worrying about the code instead of the data structure. This would be easier to address before the lines are transformed into HTML. Which I assume is not how they are stored.

Actually, they are! We host many document types on RG, not just song lyrics, so the “lyrics” field of a song is just a specific case of the general “body” field of a text. And texts can definitely have rich formatting via HTML markup.

Re: XPath is actually pretty useful once it stops being confusing

#72
post #66

XML gets a bad rap because of how much prettier JSON is, but there are a lot of cool tools associated with it. XPath is pretty awesome, I had to write a XPath parser/executor once (for a class) and it made me appreciate the value and simplicity. Then there was XSLT, which was a pretty sweet way to turn a data format into a variety of "print" or "display" formats. Definitely been replaced by bigger and better things b…

XSLT is a turing-complete programming language. Really, the moment your source XML has a slightly different structure from the target output, XSLT files become monsters. Programming in XML is never a good idea. It isn't in XSLT, it isn't in Spring, it isn't in Maven. Anything that's XML and has elements or attributes with names like "if", "else" or "while", something went horribly, horribly wrong somewhere. It's horr…

Would you say »Programming in S-expressions is never a good idea« as well?

Re: XPath is actually pretty useful once it stops being confusing

#73
post #36

> But it gets more interesting if the lyrics are stored as an HTML fragment. Is there any reason to store the HTML version with s and s instead of a plain text and converting it to HTML with simple rules à la markdown? (single line break = , double line break = )

yeah, this is super surprising considering their business of annotating individual lines; I'd be storing the lines in a list and caching generated html, not storing the tags in with them. it's kind of weird.

Re: XPath is actually pretty useful once it stops being confusing

#74
post #72

Earlier quoted context omitted.

XSLT is a turing-complete programming language. Really, the moment your source XML has a slightly different structure from the target output, XSLT files become monsters. Programming in XML is never a good idea. It isn't in XSLT, it isn't in Spring, it isn't in Maven. Anything that's XML and has elements or attributes with names like "if", "else" or "while", something went horribly, horribly wrong somewhere. It's horr…

Would you say »Programming in S-expressions is never a good idea« as well?

No. Why?

Re: XPath is actually pretty useful once it stops being confusing

#75
post #66

XML gets a bad rap because of how much prettier JSON is, but there are a lot of cool tools associated with it. XPath is pretty awesome, I had to write a XPath parser/executor once (for a class) and it made me appreciate the value and simplicity. Then there was XSLT, which was a pretty sweet way to turn a data format into a variety of "print" or "display" formats. Definitely been replaced by bigger and better things b…

XSLT is a turing-complete programming language. Really, the moment your source XML has a slightly different structure from the target output, XSLT files become monsters. Programming in XML is never a good idea. It isn't in XSLT, it isn't in Spring, it isn't in Maven. Anything that's XML and has elements or attributes with names like "if", "else" or "while", something went horribly, horribly wrong somewhere. It's horr…

I was just saying XML and XSLT is really cool, which it is. It's a tool that does one job, which at a time was a very common job.

Re: XPath is actually pretty useful once it stops being confusing

#76
post #66

XML gets a bad rap because of how much prettier JSON is, but there are a lot of cool tools associated with it. XPath is pretty awesome, I had to write a XPath parser/executor once (for a class) and it made me appreciate the value and simplicity. Then there was XSLT, which was a pretty sweet way to turn a data format into a variety of "print" or "display" formats. Definitely been replaced by bigger and better things b…

Just curious: what are the "bigger and better things" that have replaced XSLT? From what I can tell, it's still being used quite a lot, especially in the world of structured documentation. For something like transforming massive amounts of XML with a great amount of structural variety to another format, XSLT would certainly be my first choice.

I'd say a comparable new piece of technology is AngularJS + HTML + CSS with JSON as the data format. In the end you're still transforming an easily-exchanged data format to a visual display, but with all of the new things that come with Web 2.0 and the thick client model.

It still can't turn a pile of XML into a pile of PDFs though, so XSLT is definitely king in some arenas.

Re: XPath is actually pretty useful once it stops being confusing

#77
post #72

Earlier quoted context omitted.

Would you say »Programming in S-expressions is never a good idea« as well?

No. Why?

Then where do you draw the line between XML as data vs. XML as code (which seems to be bad) and sexpr as data vs. sexpr as code (which seems to be good)?

Just curious; it's just syntax, after all, and I think that XSLT really has an advantage in transforming XML to other XML (or text) compared to a program in other languages.

Post reply on HN