[gst-devel] Slimming
Joshua N Pritikin
vishnu at pobox.com
Thu Jun 21 15:52:16 CEST 2001
On Wed, Jun 20, 2001 at 10:51:32PM -0700, Erik Walthinsen wrote:
> On Thu, 21 Jun 2001, Joshua N Pritikin wrote:
> > Generating XML is much easier than parsing it. When i wrote an XML
> > generator in perl, i needed only about 40 lines of generic code to
> > complement to the application specific stuff.
>
> Oh, of course. I know that ;-)
>
> I'm just pointing out that someone has to go write it.
Well . . . my suggestion isn't completely vaporware. ;-)
The attached perl code is what i'm using. i'm not a glib expert yet so it will
take some time before i can offer a glib-ized version. Enjoy ..
--
Get self-realization at <http://sahajayoga.org> ... <http://why-compete.org> ?
Victory to the Divine Mother!!
-------------- next part --------------
{################################
## based on XML::Writer by David Megginson <david at megginson.com>
##
my @ElementStack;
my %Entity = ('&' => '&',
'<' => '<',
'>' => '>',
'"' => '"');
sub doctype {
my ($out, $t1, $t2) = @_;
print $out qq(<!DOCTYPE $t1 PUBLIC "$t2" "">\n);
}
sub characters {
my ($out, $data) = @_;
$data =~ s/([&<>])/$Entity{$1}/sgx;
print $out $data;
}
sub dataElement {
my ($out, $tag, $data, @attr) = @_;
startTag($out, $tag, @attr);
characters($out, $data);
endTag($out);
}
sub startTag {
my ($out, $tag, @attr) = @_;
push @ElementStack, $tag;
print $out "<$tag";
_showAttributes($out, @attr);
print $out "\n>";
}
sub emptyTag {
my ($out, $tag, @attr) = @_;
print $out "<$tag";
_showAttributes($out, @attr);
print $out "\n />";
}
sub endTag {
my ($out, $tag) = @_;
my $cur = pop @ElementStack;
if (!defined $cur) {
croak("End tag \"$tag\" does not close any open element");
} elsif ($tag and $cur ne $tag) {
croak("Attempt to end element \"$cur\" with \"$tag\" tag");
}
print $out "</$cur\n>";
}
sub _showAttributes {
my $out = shift;
while (@_) {
my ($k,$v) = splice @_, 0, 2;
$v =~ s/([&<>"])/$Entity{$1}/sgx;
print $out qq( $k="$v");
}
}
}
More information about the gstreamer-devel
mailing list