From: John Kitchin <jkitchin@andrew.cmu.edu>
To: stardiviner <numbchild@gmail.com>
Cc: "emacs-orgmode list" <emacs-orgmode@gnu.org>,
"Simonyi András" <andras.simonyi@gmail.com>
Subject: Re: [SOLVED] How to use xml src block as data input?
Date: Mon, 30 Apr 2018 21:14:44 -0700 [thread overview]
Message-ID: <CAJ51EToUxe5ZE3fXu-5Ag+M9TO05TsiwFwN+DB+a34aXZPYYKQ@mail.gmail.com> (raw)
In-Reply-To: <87muxk3v4a.fsf@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1984 bytes --]
all things in emacs are elisp...
You can use this function:
#+BEGIN_SRC emacs-lisp
(defun get-xml (name)
(save-excursion
(org-babel-goto-named-src-block name)
(org-element-property :value (org-element-context))))
#+END_SRC
#+RESULTS:
: get-xml
like this in a python (or other general lang) block to get the xml as a
string that you parse in the language:
#+BEGIN_SRC python :var data=(get-xml "xml-example")
import xml.etree.ElementTree as ET
root = ET.fromstring(data)
for child in root:
print(child.tag, child.attrib)
#+END_SRC
#+RESULTS:
: to {}
: from {}
: heading {}
: body {}
I don't know about noweb.
John
-----------------------------------
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
On Mon, Apr 30, 2018 at 8:36 PM, stardiviner <numbchild@gmail.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
> Thanks, John and Simonyi. This is a solution on Elisp. Not general way.
> But as a intermedia step, really workable. I chose this method.
>
> BTW, is it possible to archived with noweb reference <<xml-data>> ?
> Like
>
> #+begin_src python :var data=<<xml-data>>
> ...
> #+end_src
>
> - --
> [ stardiviner ] don't need to convince with trends.
> Blog: https://stardiviner.github.io/
> IRC(freenode): stardiviner
> GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>
> -----BEGIN PGP SIGNATURE-----
>
> iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlrn4LYACgkQG13xyVro
> msP8ywf/VaaQkpFcV16/2NDRODkC+iNN6TCp1MRJjYL9qkppa/A8vRGPZSxIG5Sd
> d2TEGx+mqRS0EANM/mhJwAIlM5U9SpycBfzasvU7R+Cn9CiehZCnJKA0dBaZiu+q
> vPBifqEqOzY873XsaRS2Xty6W4NSrh8aL6hEWxiDJSafjaCxI2FvApg2JnPi6HoC
> /sy9eSuIYvG8vCRow9y8E/GFcWE5EXoB/d/mdcEmGz80sB39Tjp4PGvLMyglROMa
> sR+8QkUTQAtDP4uEAF7biHAGE2PcELpZVLjzWm0GfZkCdJF9tH8KrEXaorB+hyHn
> MWxzlZ/gSNcsROF7DHVaZgCMMiiXuw==
> =fImh
> -----END PGP SIGNATURE-----
>
[-- Attachment #2: Type: text/html, Size: 3232 bytes --]
next prev parent reply other threads:[~2018-05-01 4:14 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
2018-05-01 3:36 ` [SOLVED] " stardiviner
2018-05-01 4:14 ` John Kitchin [this message]
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAJ51EToUxe5ZE3fXu-5Ag+M9TO05TsiwFwN+DB+a34aXZPYYKQ@mail.gmail.com \
--to=jkitchin@andrew.cmu.edu \
--cc=andras.simonyi@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=numbchild@gmail.com \
/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.