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 Veillard      | Red Hat Network
veillard redhat com  | libxml Gnome XML XSLT toolkit | Rpmfind RPM search engine

xml mailing list
xml gnome org

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.



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->read_callback(\&readme) ;

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 {

     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]