emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: "Simonyi András" <andras.simonyi@gmail.com>
Cc: emacs-orgmode list <emacs-orgmode@gnu.org>
Subject: Re: How to use xml src block as data input?
Date: Mon, 30 Apr 2018 06:34:27 -0700	[thread overview]
Message-ID: <m2fu3cx1gc.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <CAOWRwxDw8m3tf4y_HB1brDXyoJ1Qtce=o2vBKO9=ouePaaQ+OQ@mail.gmail.com>

Here is a minor variation on this idea:

#+name: xml-example
#+BEGIN_SRC xml
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
#+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 <numbchild@gmail.com> 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

  reply	other threads:[~2018-04-30 13:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-30  5:59 How to use xml src block as data input? stardiviner
2018-04-29 14:59 ` stardiviner
2018-04-29 17:30   ` John Kitchin
2018-04-30  3:42     ` stardiviner
2018-04-30  9:47       ` Simonyi András
2018-04-30 13:34         ` John Kitchin [this message]
2018-05-01  3:36           ` [SOLVED] " stardiviner
2018-05-01  4:14             ` John Kitchin
2018-05-01 13:10               ` stardiviner
2018-04-29 15:14 ` Bastien

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

  List information: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=m2fu3cx1gc.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=andras.simonyi@gmail.com \
    --cc=emacs-orgmode@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 public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).