* Use of (sxml xpath)
@ 2012-10-31 17:51 Ariel Rios
2012-10-31 21:57 ` Aleix Conchillo Flaqué
2012-11-02 16:52 ` Ian Price
0 siblings, 2 replies; 3+ messages in thread
From: Ariel Rios @ 2012-10-31 17:51 UTC (permalink / raw)
To: guile-user
[-- Attachment #1: Type: text/plain, Size: 595 bytes --]
Hello all,
I am trying to use (sxml xpath) to parse an xml file but I just cannot
understand the API.
If I have the following xml
<?xml version="1.0" encoding="UTF-8"?>
<tt xmlns="http://www.w3.org/2006/10/ttaf1" xml:lang="en">
<head><styling/><layout/></head>
<body>
<div>
<p foo="x"/>hello </p>
<p foo="y"/>hello 2 </p>
<p foo="z"/>hello 3</p>
.....
In Perl I can do something like:
my $xml = XML::XPath->new(filename => $file);
$xml->find ('//p')->get_nodelist);
$p->getAttribute ('foo')
But I just cannot find a way to do this one guile and the documentation is
not clear to me.
ariel
[-- Attachment #2: Type: text/html, Size: 1109 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Use of (sxml xpath)
2012-10-31 17:51 Use of (sxml xpath) Ariel Rios
@ 2012-10-31 21:57 ` Aleix Conchillo Flaqué
2012-11-02 16:52 ` Ian Price
1 sibling, 0 replies; 3+ messages in thread
From: Aleix Conchillo Flaqué @ 2012-10-31 21:57 UTC (permalink / raw)
To: Ariel Rios; +Cc: guile-user
On Wed, Oct 31, 2012 at 10:51 AM, Ariel Rios <ariel@gnu.org> wrote:
> Hello all,
>
> I am trying to use (sxml xpath) to parse an xml file but I just cannot
> understand the API.
>
> If I have the following xml
> <?xml version="1.0" encoding="UTF-8"?>
> <tt xmlns="http://www.w3.org/2006/10/ttaf1" xml:lang="en">
> <head><styling/><layout/></head>
> <body>
> <div>
> <p foo="x"/>hello </p>
> <p foo="y"/>hello 2 </p>
> <p foo="z"/>hello 3</p>
> .....
>
>
> In Perl I can do something like:
> my $xml = XML::XPath->new(filename => $file);
> $xml->find ('//p')->get_nodelist);
> $p->getAttribute ('foo')
>
(define (test-sxml port)
(let ((x (xml->sxml port)))
((sxpath '(// p @ foo)) x)))
(call-with-input-file "test.xml" test-sxml)
(test-sxml) will return a list like this:
((foo "x") (foo "y") (foo "z"))
Or, if you use (sxpath '(// p)) you will get all full <p>:
((p (@ (foo "x")) "hello ") (p (@ (foo "y")) "hello 2 ") (p (@ (foo
"z")) "hello 3"))
Hope this helps,
Aleix
---
I've tried it with:
<?xml version="1.0" encoding="UTF-8"?>
<body>
<div>
<p foo="x">hello </p>
<p foo="y">hello 2 </p>
<p foo="z">hello 3</p>
</div>
</body>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: Use of (sxml xpath)
2012-10-31 17:51 Use of (sxml xpath) Ariel Rios
2012-10-31 21:57 ` Aleix Conchillo Flaqué
@ 2012-11-02 16:52 ` Ian Price
1 sibling, 0 replies; 3+ messages in thread
From: Ian Price @ 2012-11-02 16:52 UTC (permalink / raw)
To: Ariel Rios; +Cc: guile-user
Ariel Rios <ariel@gnu.org> writes:
> But I just cannot find a way to do this one guile and the documentation is not clear
> to me.
Lisovsky, one of the creators of sxpath, has a number of examples at
http://www.metapaper.net/lisovsky/query/examples/xpath/
Though, I have to agree, it would be nice to get better documentation in
the manual at some point.
--
Ian Price -- shift-reset.com
"Programming is like pinball. The reward for doing it well is
the opportunity to do it again" - from "The Wizardy Compiled"
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-11-02 16:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-10-31 17:51 Use of (sxml xpath) Ariel Rios
2012-10-31 21:57 ` Aleix Conchillo Flaqué
2012-11-02 16:52 ` Ian Price
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).