How to read the Doctype Information out of an XML File

P

pod69

Hello,

How can i read the Doctype Information out of an xml file?

<!DOCTYPE foo SYSTEM "foo.dtd"
[
<!ENTITY bla SYSTEM "bla.xml">
<!ENTITY foofoo SYSTEM "foofoo.xml">
]

So that i get out e.g. in an array bla.xml and foofoo.xml?

Has someone an example? That would help me a lot!

thx pättr
 
D

DJ Stunks

Hello,

How can i read the Doctype Information out of an xml file?

<!DOCTYPE foo SYSTEM "foo.dtd"
[
<!ENTITY bla SYSTEM "bla.xml">
<!ENTITY foofoo SYSTEM "foofoo.xml">
]

So that i get out e.g. in an array bla.xml and foofoo.xml?

I would use XML::parser and write an Entity handler which pushed the
Sysid onto a globally scoped array. After it has parsed the whole file
your array will contain your entities.

-jp
 
P

pod69

Hello,
Do you have an example somewhere so i can see how it looks like because
i dont know what to do or do you have some code?
thx


DJ said:
Hello,

How can i read the Doctype Information out of an xml file?

<!DOCTYPE foo SYSTEM "foo.dtd"
[
<!ENTITY bla SYSTEM "bla.xml">
<!ENTITY foofoo SYSTEM "foofoo.xml">
]

So that i get out e.g. in an array bla.xml and foofoo.xml?

I would use XML::parser and write an Entity handler which pushed the
Sysid onto a globally scoped array. After it has parsed the whole file
your array will contain your entities.

-jp
 
D

DJ Stunks

Do you have an example somewhere so i can see how it looks like because
i dont know what to do or do you have some code?

[ please don't top post! quote an appropriate amount of context and
then post your reply underneath]

I thought my answer was pretty clear; if you're having a hard time
understanding it then I suspect you will have a hard time completing
your task. However, since I was curious I whipped this up.

Enjoy!

-jp

#!/usr/bin/perl

use strict;
use warnings;

use XML::parser;

my $xml = do{ local $/; <DATA> };

my $parser
= new XML::parser(Handlers => { Entity => \&handle_entity });

my @entities;
$parser->parse( $xml );

print "Entities:\n";
print " $_\n" for @entities;

sub handle_entity {
@_{ qw(Expat Name Val Sysid Pubid Ndata IsParam) } = @_;

push @entities, $_{Sysid};

}

__DATA__
<!-- xq226.xml -->
<!DOCTYPE poem [
<!ENTITY ext1 SYSTEM "lines938-939.xml">
]>
<poem>
<verse>I therefore, I alone first undertook</verse>
<verse>To wing the desolate Abyss, and spy</verse>
&ext1;
<verse>Better abode, and my afflicted Powers</verse>
<verse>To settle here on Earth or in mid-air</verse>
</poem>
 
P

pod69

thank you very much for your example - that was what i was looking for
- now i have a better understanding of that!


DJ said:
Do you have an example somewhere so i can see how it looks like because
i dont know what to do or do you have some code?

[ please don't top post! quote an appropriate amount of context and
then post your reply underneath]

I thought my answer was pretty clear; if you're having a hard time
understanding it then I suspect you will have a hard time completing
your task. However, since I was curious I whipped this up.

Enjoy!

-jp

#!/usr/bin/perl

use strict;
use warnings;

use XML::parser;

my $xml = do{ local $/; <DATA> };

my $parser
= new XML::parser(Handlers => { Entity => \&handle_entity });

my @entities;
$parser->parse( $xml );

print "Entities:\n";
print " $_\n" for @entities;

sub handle_entity {
@_{ qw(Expat Name Val Sysid Pubid Ndata IsParam) } = @_;

push @entities, $_{Sysid};

}

__DATA__
<!-- xq226.xml -->
<!DOCTYPE poem [
<!ENTITY ext1 SYSTEM "lines938-939.xml">
]>
<poem>
<verse>I therefore, I alone first undertook</verse>
<verse>To wing the desolate Abyss, and spy</verse>
&ext1;
<verse>Better abode, and my afflicted Powers</verse>
<verse>To settle here on Earth or in mid-air</verse>
</poem>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top