[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Use of (sxml xpath)
From: |
Aleix Conchillo Flaqué |
Subject: |
Re: Use of (sxml xpath) |
Date: |
Wed, 31 Oct 2012 14:57:14 -0700 |
On Wed, Oct 31, 2012 at 10:51 AM, Ariel Rios <address@hidden> 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>