1 |
* Mike Frysinger (vapier@g.o) wrote: |
2 |
> On Friday 07 September 2007, Alec Warner wrote: |
3 |
> > On 9/7/07, Doug Goldstein <cardoe@g.o> wrote: |
4 |
> > > Sure... be fancy with all your xsl and xml crap. LONG LIVE THE BRUTE |
5 |
> > > FORCE PARSE WITH SED! |
6 |
> > |
7 |
> > People who parse xml with sed make me cry. |
8 |
> > |
9 |
> > grep = also bad. |
10 |
> |
11 |
> i'd parse it with xmlgawk if i hadnt punted it from gawk sometime ago |
12 |
> -mike |
13 |
|
14 |
app-text/xml2 makes a surprisingly nice replacement for xmlgawk for |
15 |
people who know not to use sed or awk on XML, yet still want to. For |
16 |
example: |
17 |
|
18 |
$ xml2 < /var/lib/repos/gentoo/sys-apps/busybox/metadata.xml \ |
19 |
| awk -F= '/\/herd=/ {print $2}' |
20 |
embedded |
21 |
$ xml2 < /var/lib/repos/gentoo/www-client/surfraw/metadata.xml \ |
22 |
| sed '/\/maintainer\/email=/!d;s,^.*=,,' |
23 |
jnrowe@×××××.org |
24 |
seemant@g.o |
25 |
|
26 |
or to match Vapier's output just collapse the output: |
27 |
|
28 |
$ echo $(xml2 < /var/lib/repos/gentoo/www-client/surfraw/metadata.xml \ |
29 |
| awk -F '/\/maintainer\/email=/ {print $2}') |
30 |
jnrowe@×××××.org seemant@g.o |
31 |
|
32 |
The above examples will cope with cases that will break the simple sed |
33 |
version, such as "<herd>\ndata\n</herd>". But then again so does |
34 |
Vapier's xsltproc solution. |
35 |
|
36 |
As a hint for other tasks the package can cope with tagsoup too if |
37 |
called with html2, and it can reassemble with 2xml/2html. There is some |
38 |
documentation online at the author's website, but its usage is obvious. |
39 |
|
40 |
Thanks, |
41 |
|
42 |
James |