* How to use xml src block as data input?
@ 2018-03-30 5:59 stardiviner
2018-04-29 14:59 ` stardiviner
2018-04-29 15:14 ` Bastien
0 siblings, 2 replies; 10+ messages in thread
From: stardiviner @ 2018-03-30 5:59 UTC (permalink / raw)
To: org-mode
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
I have a xml src block like this:
#+NAME: xml-sample
#+begin_src xml
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Example Feed</title>
<link href="http://example.org/"/>
<updated>2003-12-13T18:30:02Z</updated>
<author>
<name>John Doe</name>
</author>
<id>urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6</id>
<entry>
<title>Atom-Powered Robots Run Amok</title>
<link rel="alternate" href="http://example.org/2003/12/13/atom03"/>
<id>urn:uuid:1225c695-cfb8-4ebb-aaaa-80da344efa6a</id>
<updated>2003-12-13T18:30:02Z</updated>
<summary>Some text.</summary>
</entry>
</feed>
#+end_src
How can I use this xml data as input in another src block?
I tried like this:
#+begin_src emacs-lisp :var sample=xml-sample
(elfeed-xml-parse-region sample)
#+end_src
But it reports no org-babel-execute for xml!
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlq90i4ACgkQG13xyVro
msNFbgf+KgmjYmlNryZ9m63UBOmpCUhQ0zkwGQWzwYs7imvfhmPGBjYR/kIVyIp6
PDi7vlT6KfzewNxOSXAH8gM2Vgy61rbzEdZNqNAEpZC+Xeigh0gh7Zllajj7pSBA
6MiyzLO5fAsh0QsYHW3ZvCME1uFHe1g7zI9ojhdHgOoPW/U2jVw5VkY+PbnEA/jd
U5CsxoN562HWpvHTwHQX7cmRbm8xCx3zcyyKZyuxTNoCE2Js/ylyJIfZTnAJDd4o
IQj1pR0jIizvB4BR5E5DHXXLTAfYXfZJQYqFyY8eDgAvbZ/V9TURqGGhoXLCiH6T
DmnnObUBPJwBC2LK+VcvxFo4BE1oDw==
=F3Fs
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
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-29 15:14 ` Bastien
1 sibling, 1 reply; 10+ messages in thread
From: stardiviner @ 2018-04-29 14:59 UTC (permalink / raw)
To: org-mode
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
Is there somebody have any idea or hints about this question?
- --
[ stardiviner ] don't need to convince with trends.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlrl3cUACgkQG13xyVro
msPaMAgAm6tqsqydqzQjK0a8564JUX+GpP/YBa+WajidIoW7FFY0xpcyV6J1kbYg
3nTwmVykJ6DiFVQZS2h2dazdn/pQHkkTgMKSvI6XHUVIFCNxC+12bJgQQ5dQJZuX
gbctNMQoXFL6YDBbil2ky2NM8mZRiQcBMyo5B2okiVGxd8CV7Ko+Bu5J1mq/3HJb
assmXwXQiUOkmHBK29soT7Fa9iVWtk96PSmL/tzEdO9G2zyE5aDtnPT+iFSlUgqi
vVCvLhYPsjyYZ7r19swTyZbeVH0av7GzqdJB18jpe1XvwBKJzdicAMP0ilJ1D4c2
jJFyOETQDkG+T1XQYqU7u94e79tJHg==
=P1VJ
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
2018-04-29 14:59 ` stardiviner
@ 2018-04-29 17:30 ` John Kitchin
2018-04-30 3:42 ` stardiviner
0 siblings, 1 reply; 10+ messages in thread
From: John Kitchin @ 2018-04-29 17:30 UTC (permalink / raw)
To: numbchild; +Cc: org-mode
Here is one approach:
#+name: xml-data
#+BEGIN_EXAMPLE
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
#+END_EXAMPLE
#+BEGIN_SRC python :var data=xml-data
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 {}
#+BEGIN_SRC emacs-lisp :var data=xml-data
(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!) |
stardiviner writes:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA256
>
>
> Is there somebody have any idea or hints about this question?
>
> - --
> [ stardiviner ] don't need to convince with trends.
> Blog: https://stardiviner.github.io/
> IRC(freenode): stardiviner
> GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
>
> -----BEGIN PGP SIGNATURE-----
>
> iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlrl3cUACgkQG13xyVro
> msPaMAgAm6tqsqydqzQjK0a8564JUX+GpP/YBa+WajidIoW7FFY0xpcyV6J1kbYg
> 3nTwmVykJ6DiFVQZS2h2dazdn/pQHkkTgMKSvI6XHUVIFCNxC+12bJgQQ5dQJZuX
> gbctNMQoXFL6YDBbil2ky2NM8mZRiQcBMyo5B2okiVGxd8CV7Ko+Bu5J1mq/3HJb
> assmXwXQiUOkmHBK29soT7Fa9iVWtk96PSmL/tzEdO9G2zyE5aDtnPT+iFSlUgqi
> vVCvLhYPsjyYZ7r19swTyZbeVH0av7GzqdJB18jpe1XvwBKJzdicAMP0ilJ1D4c2
> jJFyOETQDkG+T1XQYqU7u94e79tJHg==
> =P1VJ
> -----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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
2018-04-29 17:30 ` John Kitchin
@ 2018-04-30 3:42 ` stardiviner
2018-04-30 9:47 ` Simonyi András
0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2018-04-30 3:42 UTC (permalink / raw)
To: John Kitchin; +Cc: org-mode
-----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-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
2018-04-30 3:42 ` stardiviner
@ 2018-04-30 9:47 ` Simonyi András
2018-04-30 13:34 ` John Kitchin
0 siblings, 1 reply; 10+ messages in thread
From: Simonyi András @ 2018-04-30 9:47 UTC (permalink / raw)
To: numbchild; +Cc: emacs-orgmode list, John Kitchin
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-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
2018-04-30 9:47 ` Simonyi András
@ 2018-04-30 13:34 ` John Kitchin
2018-05-01 3:36 ` [SOLVED] " stardiviner
0 siblings, 1 reply; 10+ messages in thread
From: John Kitchin @ 2018-04-30 13:34 UTC (permalink / raw)
To: Simonyi András; +Cc: emacs-orgmode list
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
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [SOLVED] How to use xml src block as data input?
2018-04-30 13:34 ` John Kitchin
@ 2018-05-01 3:36 ` stardiviner
2018-05-01 4:14 ` John Kitchin
0 siblings, 1 reply; 10+ messages in thread
From: stardiviner @ 2018-05-01 3:36 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode list, Simonyi András
-----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-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [SOLVED] How to use xml src block as data input?
2018-05-01 3:36 ` [SOLVED] " stardiviner
@ 2018-05-01 4:14 ` John Kitchin
2018-05-01 13:10 ` stardiviner
0 siblings, 1 reply; 10+ messages in thread
From: John Kitchin @ 2018-05-01 4:14 UTC (permalink / raw)
To: stardiviner; +Cc: emacs-orgmode list, Simonyi András
[-- 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 --]
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [SOLVED] How to use xml src block as data input?
2018-05-01 4:14 ` John Kitchin
@ 2018-05-01 13:10 ` stardiviner
0 siblings, 0 replies; 10+ messages in thread
From: stardiviner @ 2018-05-01 13:10 UTC (permalink / raw)
To: John Kitchin; +Cc: emacs-orgmode list, Simonyi András
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
This is great. Thanks John.
- --
[ stardiviner ] don't need to convince with trends.
Blog: https://stardiviner.github.io/
IRC(freenode): stardiviner
GPG: F09F650D7D674819892591401B5DF1C95AE89AC3
-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEE8J9lDX1nSBmJJZFAG13xyVromsMFAlroZzkACgkQG13xyVro
msO8kQf+OhzChdi9GRrjKEJOQNod2Gg9g86eGBu5w97ZOHgj/MkOzu2jd3AMxKDN
mt6LKXmcJCDEzKIO36xiiypdckwfU98zAZGrpLFbUlYZ3wdLT/HY1XWXkOHGiQvk
h6rxi7jWdkKw4/tSMZ/Mh70bJ803Y2jZ5JnKx4hwVlgBfoettgWfRf6h91Zg/VcU
QDrIMG5aYcgoMA0GwWtOWeYuYIkq18/Elg6gQhSg+vIe0s0U/4qoArlIFL0AoZcF
qwBZ1hBukWOf1gHvvI8rjbqQ4BOFFjDSbPS6/C+NMZL7oDkbpErH5JAaZTsYYH5e
QBLsOjao+bG1d+7TtZzD92kAsWN5Kg==
=/XVs
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: How to use xml src block as data input?
2018-03-30 5:59 How to use xml src block as data input? stardiviner
2018-04-29 14:59 ` stardiviner
@ 2018-04-29 15:14 ` Bastien
1 sibling, 0 replies; 10+ messages in thread
From: Bastien @ 2018-04-29 15:14 UTC (permalink / raw)
To: stardiviner; +Cc: org-mode
Hi,
stardiviner <numbchild@gmail.com> writes:
> How can I use this xml data as input in another src block?
You would need to enclose the xml code within #+begin_example instead
of #+begin_src. Also, elfeed-xml-parse-region will not work on a
string, it expects other arguments, so you might need to write your
own parsing function, maybe based on libxml-parse-xml-region if your
version of Emacs has libxml support.
HTH,
--
Bastien
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2018-05-01 13:10 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2018-05-01 13:10 ` stardiviner
2018-04-29 15:14 ` Bastien
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.