Re: [xml] Perl XML::LibXML



Daniel Veillard wrote:

On Wed, Jun 13, 2001 at 11:31:04PM -0700, root wrote:
Hello I am trying to use the XML::LibXML::Dtd->new method to create a
dtd object. I need to be able to pass the dtd as a string variable and
not a URI or File name. Is this possible at all.

  hum, I can't tell for the Perl interfaces. At the C level, the
xmlIOParseDTD() routine allows to parse from a xmlParserInputBufferPtr.
And xmlParserInputBufferPtr can be build from a string in memory, so
I think this is feasible at that level.

Daniel

--
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/

_______________________________________________
xml mailing list
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml

Thanks for your help but I have found the perl solution. It is rather simple.

IO::Scalar is a class that allows you to treat an string as an IO stream.
This with the callbacks seems to
work just fine.


Sample



#!/usr/bin/perl

use XML::LibXML;
use XML::LibXSLT;
use IO::Scalar;


open(XSL, "//xml/xsl/crt_baccount_ndc-in.xsl") or die "No XSL\n";
open(XML, "//xml/xml/crt_baccount_ndc.xml") or die "No XML\n";
open(DTD, "//xml/dtd/crt_baccount_ndc.dtd") or die "No DTD\n";
my $xsl = join("", <XSL>);
my $dtd = join('', <DTD>);
my $xml = join('', <XML>);

XML::LibXML->validation(1);
XML::LibXML->load_ext_dtd(1);

XML::LibXML->read_callback(\&readme) ;
XML::LibXML->match_callback(\&matchme);
XML::LibXML->open_callback(\&openme);
XML::LibXML->close_callback(\&closeme);

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();
my $DTD = IO::Scalar->new();

my $source = $parser->parse_string($xml);
my $dtdobj = XML::LibXML::Dtd->new("0", "0");

$is_it_valid = $source->is_valid($dtdobj), "\n";

}

sub matchme {
    return 1;
}

sub openme {

    $DTD->open(\$dtd);
     return $DTD;
}

sub readme {
     my $handler = shift;
     my $length = shift;
     my $buffer;
     $handler->sysread($buffer, $length) if ($handler);
     return $buffer;
}

sub closeme {}







[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]