List Info

Thread: perl-ish way to deal with footnotes in an XML document




perl-ish way to deal with footnotes in an XML document
country flaguser name
Austria
2007-07-19 10:18:19
Hello,

please forgive me if this is a somewhat uninformed
question.

I have an XML document that is to be transformed both into
HTML and 
LaTeX Code. This is a critical edition which contains
several layers of 
critical notes. The notes need anchors in the text, of
course, either as 
classical footnote anchors or as LaTeX commands wrapped
around a string 
of text that serves as an anchor (which LaTeX then keys to
the line 
number in the printed document).

I'd prefer to do all the necessary transformations with
perl; I'm using 
XML::LibXML. The point I'm stuck at the moment is to handle
footnote 
anchors.

Consider this chunk of code:

<seg>This is a segment of text. It goes on and on.
<note><span 
type="lemma">Here</span>
<app>
    <lem>Here</lem>
    <rdg wit="Ms-A">Here</rdg>
    <rdg wit="Ms-B">There</rdg>
</app>
</note>
there is a note, but after the note the text
continues.</seg>

How can I get whatever code I wish to create for the note to
be inserted 
*exactly* at the start of the <note>-Element, that is,
at a specified 
position in the text content of its parent? I couldn't find
anything in 
the XML::LibXML documentation, but maybe I just didn't know
the right 
terminology.

Thanks in advance for any help,

Birgit Kellner





_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

RE: perl-ish way to deal with footnotes in an XML document
country flaguser name
United States
2007-07-19 10:37:47
Birgit Kellner wrote:
> <seg>This is a segment of text. It goes on and
on. <note><span
> type="lemma">Here</span>
> <app>
>     <lem>Here</lem>
>     <rdg wit="Ms-A">Here</rdg>
>     <rdg wit="Ms-B">There</rdg>
> </app>
> </note>
> there is a note, but after the note the text
continues.</seg>
> 
> How can I get whatever code I wish to create for the
note to be
> inserted
> *exactly* at the start of the <note>-Element, 

Each text segment is a different node. In other words,
<seg> has three
children:
1. A text node containing "This is a segment... on and
on. "
2. A <note> element
3. A text node containing "there is a note...
continues."

So doing what you want to do is not a problem.

- Mark.

_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: perl-ish way to deal with footnotes in an XML document
country flaguser name
Austria
2007-07-19 11:48:32
Thomas, Mark - BLS CTR schrieb:
> Birgit Kellner wrote:
>   
>> <seg>This is a segment of text. It goes on
and on. <note><span
>> type="lemma">Here</span>
>> <app>
>>     <lem>Here</lem>
>>     <rdg
wit="Ms-A">Here</rdg>
>>     <rdg
wit="Ms-B">There</rdg>
>> </app>
>> </note>
>> there is a note, but after the note the text
continues.</seg>
>>
>> How can I get whatever code I wish to create for
the note to be
>> inserted
>> *exactly* at the start of the <note>-Element,

>>     
>
> Each text segment is a different node. In other words,
<seg> has three
> children:
> 1. A text node containing "This is a segment... on
and on. "
> 2. A <note> element
> 3. A text node containing "there is a note...
continues."
>
> So doing what you want to do is not a problem.
>
> - Mark.
>
>
>   
That's good to know. Do you have any suggestions how exactly
I might go 
about it, then?

I tried this with XML::LibXML:

my $children = $seg->findnodes('child:');
    foreach my $child ($children->get_nodelist) {
        print $child->textContent ;
        my $name = $child->nodeName;
        print "$name n";
}

While the code correctly returns the <note>-Element,
it doesn't return 
the text node; actually it returns the text content of
<seg>; instead, 
it returns the text content of all <rdg>-elements.

Thanks,

Birgit

_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

RE: perl-ish way to deal with footnotes in an XML document
country flaguser name
United States
2007-07-19 13:35:24
> That's good to know. Do you have any suggestions how
exactly I might
> go
> about it, then?
> 
> I tried this with XML::LibXML:
> 
> my $children = $seg->findnodes('child:');
>     foreach my $child ($children->get_nodelist) {
>         print $child->textContent ;
>         my $name = $child->nodeName;
>         print "$name n";
> }

I'm pretty sure * returns only elements, not text nodes. Try
this
instead:

foreach my $child ($seg->childNodes) {
    my $name = $child->nodeName;
    print "$namen";
}

- Mark.

_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

Re: perl-ish way to deal with footnotes in an XML document
country flaguser name
Austria
2007-07-19 14:48:18
Thomas, Mark - BLS CTR schrieb:
>> That's good to know. Do you have any suggestions
how exactly I might
>> go
>> about it, then?
>>
>> I tried this with XML::LibXML:
>>
>> my $children = $seg->findnodes('child:');
>>     foreach my $child ($children->get_nodelist)
{
>>         print $child->textContent ;
>>         my $name = $child->nodeName;
>>         print "$name n";
>> }
>>     
>
> I'm pretty sure * returns only elements, not text
nodes. Try this
> instead:
>
> foreach my $child ($seg->childNodes) {
>     my $name = $child->nodeName;
>     print "$namen";
> }
>
> - Mark.
>
>
>   
That's it!

my $test;
my children = $seg->childNodes;
foreach my $child (children) {
    my $name = $child->nodeName;
    if ($name eq "text") { $test .=
$child->textContent ;}
    elsif ($name eq "note") { $test .=
"NOTECODE";}
}
print $test;


Many thanks for pointing me into the right direction,

Birgit

_______________________________________________
Perl-XML mailing list
Perl-XMLlistserv.ActiveState.com
To unsubscribe: http:/
/listserv.ActiveState.com/mailman/mysubs

[1-5]

about | contact  Other archives ( Real Estate discussion Medical topics )