Re: Using XML::LibXML::SAX::Parser as replacement for XML::LibXML::SAX::Generator

Kjetil Kjernsmo <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Message-ID <[email protected]>
On Wednesday 7. April 2010 14:52:57 The Distinguished Dahut Robin wrote:

> Heh. Possibly the hardest thing in XML is picking the right tool for any
>  given task. There are cases in which using XSLT is a PITA, and others
>  where it shines; and the same applies to pretty much anything else.

Yup :-)

> It does indeed look like your case requires more processing than I'd be
>  happy to do with XSLT, so something Perl-based sounds good.

OK, good! :-)


> Actually, the primary reason why XSLT is a bad match is mostly because
>  it doesn't have any SPARQL support, and limited HTTP support (only the
>  simplest GETs). If you were getting information in XML from given URIs
>  in the source document, you could rather easily use XSLT for this task
>  (with the document() function).

Right!

> >> Kjetil: do you have some code to show us so we could advise options?
> >
> > Sure! My RDF::RDFa::Template module (not yet on CPAN) is the example
> > :-) More specifically, it would be great if you had a look at the
> > current SAX Filter:
> > http://svn.kjernsmo.net/RDF-RDFa-Template/trunk/lib/RDF/RDFa/Template/
> >SAXFilter.pm
> 
> So, this is not at all a complete port of your code, it's just an
>  example of how it can be done with Perl using XPath to power the
>  transformations:

Great, thanks! I've actually just released my code:
http://search.cpan.org/dist/RDF-RDFa-Template/
but with a long TODO list. :-) It would be great if people poked at it, the 
idea is to make it easy to create simple Semantic Web driven pages. It is 
an early alpha/proof-of-concept/discussion item kinda thing now, but all 
the more reason to poke at it :-)

Anyway, on the top of the TODO-list is the fact that I need something to 
treat SPARQL queries with more than one solution, so I need to do some 
looping and stuff. I think I will revisit your code when I need to solve 
this problem.

> Assuming your namespace declarations are all on the root element, that
>  $doc holds the Document, and that the namespace isn't used by any
>  attribute or element in the context (it would still work, but you'd be
>  getting side-effects), the following should work:

Actually, switching to X:L:SAX::Parser was a decent solution.
 
> > the doctype declaration,
> 
> Still assuming $doc holds the Document, with $root from above, and
>  $pubId and $sysId retrieved from the proper places:
> 
> $doc->setExternalSubset($doc->createExternalSubset($root->tagName,
>  $pubId, $sysId));

Hmmm, I tried 
my $xpc = XML::LibXML::XPathContext->new($orig);
$xpc->registerNs('rat', $self->{DOC}->{RATURI});
$xpc->registerNs('xhtml', 'http://www.w3.org/1999/xhtml');
my ($system_id) = $xpc->findnodes('/xhtml:html/@rat:doctype-system') || 
'http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd';
my ($public_id) = $xpc->findnodes('/xhtml:html/@rat:doctype-public') || 
'-//W3C//DTD XHTML+RDFa 1.0//EN';
my $dtd = XML::LibXML::Dtd->new($public_id, $system_id); 
my $output = $builder->result;
$output->setExternalSubset($dtd);

But that took ages to run, and I assumed that XML::LibXML::Dtd tried to 
download the resource identified by the system ID... Does your code do the 
same thing? I just want to prefix the string... :-)



> > and finally, package a simple
> > HTTP::Server::Simple script for people to try it out.
> 
> For that, you're on your own :)

Actually, it was very easy! :-)
 
Cheers,

Kjetil
-- 
Kjetil Kjernsmo
[email protected]
http://www.kjetil.kjernsmo.net/
_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.