Re: xml-parse: file position of elements

Joseph Donaldson <[email protected]> Fri, 4 Feb 2022 16:28:10 +0000 (UTC)
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <[email protected]>
------=_Part_191438_600140723.1643992090281
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

 Hello, Sven,
That will teach me to spot test using emacs which I now see uses 1-based ch=
aracter positioning. I will take a look at the issue reported below.
Best Regards,Joe

    On Thursday, February 3, 2022, 11:27:18 PM PST, Sven Hartrumpf <hartrum=
[email protected]> wrote: =20
=20
 Hello Joe.

Joseph Donaldson, 2022-02-01 18:21:
> Hello, Sven,
> Here is an updated version that moves the start-position parameter to pos=
ition 4 and has the value of the element's starting < character.
> I also removed some debugging print statements that were erroneously left=
 in place. Let me know how it works for you.

Thanks for the new version!

I removed the (+ . 1) in your helper function update-start-position!
because file offsets and string offsets are normally 0-based in Scheme.
The following code

=C2=A0 (call-with-input-string
=C2=A0 =C2=A0 "<doc><itm></itm></doc><doc><itm></itm></doc>"
=C2=A0 =C2=A0 (lambda (port)
=C2=A0 =C2=A0 =C2=A0 (pp (xml-parse port :procedure list :encoding 'UTF-8))=
))

outputs:

((doc () ((itm () () 0)) 0)
 (doc () ((itm () () 22)) 22))

The offsets for the doc-elements are correct,
the ones for the itm-elements are not?

Best regards
Sven
 =20
------=_Part_191438_600140723.1643992090281
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

<html><head></head><body><div class=3D"ydpe44cecf0yahoo-style-wrap" style=
=3D"font-family: Helvetica Neue, Helvetica, Arial, sans-serif; font-size: 1=
3px;"><div></div>
        <div dir=3D"ltr" data-setdir=3D"false">Hello, Sven,</div><div dir=
=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-setdir=3D"fa=
lse">That will teach me to spot test using emacs which I now see uses 1-bas=
ed character positioning. I will take a look at the issue reported below.</=
div><div dir=3D"ltr" data-setdir=3D"false"><br></div><div dir=3D"ltr" data-=
setdir=3D"false">Best Regards,</div><div dir=3D"ltr" data-setdir=3D"false">=
Joe<br></div><div><br></div>
       =20
        </div><div id=3D"ydp6b16f654yahoo_quoted_4549395273" class=3D"ydp6b=
16f654yahoo_quoted">
            <div style=3D"font-family:'Helvetica Neue', Helvetica, Arial, s=
ans-serif;font-size:13px;color:#26282a;">
               =20
                <div>
                    On Thursday, February 3, 2022, 11:27:18 PM PST, Sven Ha=
rtrumpf &lt;[email protected]&gt; wrote:
                </div>
                <div><br></div>
                <div><br></div>
                <div><div dir=3D"ltr">Hello Joe.<br clear=3D"none"><br clea=
r=3D"none">Joseph Donaldson, 2022-02-01 18:21:<br clear=3D"none">&gt; Hello=
, Sven,<br clear=3D"none">&gt; Here is an updated version that moves the st=
art-position parameter to position 4 and has the value of the element's sta=
rting &lt; character.<br clear=3D"none">&gt; I also removed some debugging =
print statements that were erroneously left in place. Let me know how it wo=
rks for you.<br clear=3D"none"><br clear=3D"none">Thanks for the new versio=
n!<br clear=3D"none"><br clear=3D"none">I removed the (+ . 1) in your helpe=
r function update-start-position!<br clear=3D"none">because file offsets an=
d string offsets are normally 0-based in Scheme.<br clear=3D"none">The foll=
owing code<br clear=3D"none"><br clear=3D"none">&nbsp; (call-with-input-str=
ing<br clear=3D"none">&nbsp; &nbsp; "&lt;doc&gt;&lt;itm&gt;&lt;/itm&gt;&lt;=
/doc&gt;&lt;doc&gt;&lt;itm&gt;&lt;/itm&gt;&lt;/doc&gt;"<br clear=3D"none">&=
nbsp; &nbsp; (lambda (port)<br clear=3D"none">&nbsp; &nbsp; &nbsp; (pp (xml=
-parse port :procedure list :encoding 'UTF-8))))<br clear=3D"none"><br clea=
r=3D"none">outputs:<br clear=3D"none"><br clear=3D"none">((doc () ((itm () =
() 0)) 0)<br clear=3D"none"> (doc () ((itm () () 22)) 22))<br clear=3D"none=
"><br clear=3D"none">The offsets for the doc-elements are correct,<br clear=
=3D"none">the ones for the itm-elements are not?<br clear=3D"none"><br clea=
r=3D"none">Best regards<div class=3D"ydp6b16f654yqt5443927987" id=3D"ydp6b1=
6f654yqtfd77879"><br clear=3D"none">Sven<br clear=3D"none"></div></div></di=
v>
            </div>
        </div></body></html>
------=_Part_191438_600140723.1643992090281--