From mboxrd@z Thu Jan 1 00:00:00 1970 From: John Kitchin Subject: Re: How to use xml src block as data input? Date: Mon, 30 Apr 2018 06:34:27 -0700 Message-ID: References: <87efk214uq.fsf@gmail.com> <87d0yidpoa.fsf@gmail.com> <87a7tl8imb.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:35755) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fD8ws-0005VW-T0 for emacs-orgmode@gnu.org; Mon, 30 Apr 2018 09:34:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fD8wr-0006Q8-GF for emacs-orgmode@gnu.org; Mon, 30 Apr 2018 09:34:34 -0400 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]:42611) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1fD8wr-0006Pk-9H for emacs-orgmode@gnu.org; Mon, 30 Apr 2018 09:34:33 -0400 Received: by mail-pf0-x22b.google.com with SMTP id a11so6747152pfn.9 for ; Mon, 30 Apr 2018 06:34:33 -0700 (PDT) In-reply-to: List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: "Emacs-orgmode" To: Simonyi =?utf-8?Q?Andr=C3=A1s?= Cc: emacs-orgmode list Here is a minor variation on this idea: #+name: xml-example #+BEGIN_SRC xml Tove Jani Reminder Don't forget me this weekend! #+END_SRC #+BEGIN_SRC emacs-lisp :var name="xml-example" (save-excursion (org-babel-goto-named-src-block name) (let ((data (org-element-property :value (org-element-context)))) (with-temp-buffer (insert data) (libxml-parse-xml-region (point-min) (point-max))))) #+END_SRC #+RESULTS: | note | nil | (to nil Tove) | (from nil Jani) | (heading nil Reminder) | (body nil Don't forget me this weekend!) | Simonyi AndrĂ¡s writes: > Hello, > > if having the data in a source block is a must, then, as a last resort, > you might try to pull the block's content from the buffer's parse tree: > > #+begin_src emacs-lisp :var src-block-name="xml-sample" > (let ((xml-str > (org-element-map (org-element-parse-buffer) 'src-block > (lambda (x) > (and (string= src-block-name (org-element-property :name x)) > (org-element-property :value x))) > nil t))) > (with-temp-buffer (insert xml-str) (libxml-parse-xml-region (point-min) > (point-max)))) > #+end_src > On Mon, 30 Apr 2018 at 05:43, stardiviner wrote: > >> -----BEGIN PGP SIGNED MESSAGE----- >> Hash: SHA256 > > >> Thanks, I forgot to mention I know example block can be used as input. >> But this will lose the syntax highlighting. If there is no better > solution. >> I guess it is the best for now. > >> - -- >> [ stardiviner ] don't need to convince with trends. >> Blog: https://stardiviner.github.io/ >> IRC(freenode): stardiviner >> GPG: F09F650D7D674819892591401B5DF1C95AE89AC3 >> -----BEGIN PGP SIGNATURE----- > >> iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlrmkL0ACgkQG13xyVro >> msOU6gf/UNiTzSt8Cizpk1FLBjJJiqOMfWdvp+jJVoNOCJzaxkHFAiwjbEyIf9B5 >> k27Zw3Gh60rT0iz/RYscptv2keTieUwU0rf23oyouFESgIBaICfRRYzZZ0ZUWTHO >> 9VGILsaQfOZfO4lenZGMnWGt583DCV1CxEqcODQj2Z7DFb8EfxvRiGup9qPjMSVq >> 65gu7/Vk2Y2d+cvUZU7t592b7D/5na5Dxy0jkuAEttXjoJrk4OHoxcmYMjbnoimq >> DSUyu467YqtKKyyOgC8hEnatarkItDp6O5v/P8Ki/iVV5zSTiqkhriQYI9k/sPTV >> xmI9WZEFOB5A8auvw9csQTUUny2Mjw== >> =qQac >> -----END PGP SIGNATURE----- -- Professor John Kitchin Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu