all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Len Blanks <ltb@haruspex.net>
To: help-gnu-emacs@gnu.org
Subject: Re: Troubles in Regular Expression Paradise
Date: Wed, 14 May 2014 17:07:11 -0500	[thread overview]
Message-ID: <m2fvkc6mls.fsf@haruspex.net> (raw)
In-Reply-To: <87oaz0ilei.fsf@geodiff-mac3.ulb.ac.be> (Nicolas Richard's message of "Wed, 14 May 2014 14:40:05 +0200")

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> Len Blanks <ltb@haruspex.net> writes:
>> I'm trying to parse an xml file containing information for a song "currently playing"
>> on my iTunes - specifically the artist, name of the tune and the CD in appears on.
>
>> and here is a function I had hoped would strip the relevant fields and return a string in
>> the form: "_artist_'s _title_ from the CD _album_" to be inserted in a X-NOW-PLAYING:
>> header in emails and usenet posts:
>
> The regexp question was answered, so I allow myself to mention
> libxml-parse-xml-region instead of regexps for parsing xml.
>
> First eval:
> (setq yftest (libxml-parse-html-region (point-min) (point-max)))
> in a buffer which holds your file.
>
> Then you can get away with:
> (caddr (assoc 'title (caddr yftest)))
> (caddr (assoc 'artist (caddr yftest)))
> (caddr (assoc 'album (caddr yftest)))
> to get the title, artist and album respectively.
>
> As a side note, I wrote some elisp for using the kind of data that
> libxml-parse-html-region spits out, so here's my way of solving your
> problem with my code :
>
> (require 'tree-html)
> ;; https://github.com/YoungFrog/tree-html/blob/master/tree-html.el
>
> (defun yf/get-value-for-sole-subtree-with-given-tag (tree tag)
>   "Assume there's exactly one XML element with given TAG in TREE, and return its
> associated value."
>   (yf/tree-html-get-value
>    (yf/tree-html-get-sole-element
>     (yf/tree-html-select
>      tree
>      (lambda (tree)
>        (eq tag (yf/tree-html-get-tag tree)))))))
>
> (format "%s's %s from the CD %s"
>         (yf/get-value-for-sole-subtree-with-given-tag yftest 'artist)
>         (yf/get-value-for-sole-subtree-with-given-tag yftest 'title)
>         (yf/get-value-for-sole-subtree-with-given-tag yftest 'album))
>
> (Yes, I'm *that* bad at naming things.)

I need to do a better job researching what is available, rather than
reinventing the wheel.  Thanks very much; I'll redo what I have using
libxml and your code to compare and learn.

Regards,
-- 
Len

Je suis Marxiste - tendance Groucho
            -- Slogan used at Nanterre in Paris, 1968




  reply	other threads:[~2014-05-14 22:07 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-14  2:18 Troubles in Regular Expression Paradise Len Blanks
2014-05-14 12:40 ` Nicolas Richard
2014-05-14 22:07   ` Len Blanks [this message]
     [not found] <mailman.1280.1400034904.1147.help-gnu-emacs@gnu.org>
2014-05-14  2:56 ` Joost Kremers
2014-05-14  3:13   ` Len Blanks

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2fvkc6mls.fsf@haruspex.net \
    --to=ltb@haruspex.net \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.