Link to home
Create AccountLog in
Web Languages and Standards

Web Languages and Standards

--

Questions

--

Followers

Top Experts

Avatar of Peewee
Peewee

XML::Libxml
I would like an example of how to validate an xml document with an external dtd, ie the XML document will have no reference to the Dtd, you have to specify this to Libxml.  i know this is possible as Libxml states it is, but i cannot get this to work.

i'll award the points for a working piece of code, an example xml document or dtd is not needeed, just the perl.

cheers
Peewee

Zero AI Policy

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.


ASKER CERTIFIED SOLUTION
Avatar of olalouxolaloux

Link to home
membership
Log in or create a free account to see answer.
Signing up is free and takes 30 seconds. No credit card required.
Create Account

Avatar of PeeweePeewee

ASKER

olaloux,

many thanks for your reply, your example was complete, but it is not quite what i asked for, the xml i am processing will not have the dtd definition i must specify with Libxml what one to use.

hence if you change your input xml to:

<?xml version="1.0" encoding="ISO-8859-1"?>
<countrieslist>
 <countries count="2">
   <country id="1234">
     <name>
       <en>Italy</en>
       <fr>Italie</fr>
     </name>
   </country>
   <country id="7890">
     <name>
       <en>Spain</en>
       <fr>Espagne</fr>
     </name>
   </country>
 </countries>
</countrieslist>

how do i get libxml to parse it then?

many thanks
Peewee

Oki doki!

# Here is the code, the XML does not contain DTD

use strict;
use XML::LibXML;
use IO::Handle;

# Load the DTD
my $dtd=XML::LibXML::Dtd->new("SOME // Public / ID / 1.0","countrieslist.dtd"); # Public part can stay empty ;-)
# Let's start the parsing
my $document=XML::LibXML->new->parse_file("countrieslist.xml");
eval {
  $document->validate($dtd);
}
if ($@ eq '') { # The $@ could contain the error
  print "XML valid.\n";
} else {
  print "XML not valid 'cause of $@ !\n";
}

In my sample, you can erase the line "use IO::Handle", it stay from previous code ;-)

Reward 1Reward 2Reward 3Reward 4Reward 5Reward 6

EARN REWARDS FOR ASKING, ANSWERING, AND MORE.

Earn free swag for participating on the platform.


Avatar of PeeweePeewee

ASKER

olaloux,

what does this mean? and what is a more sensible value for it, can you provide some examples of what they could be:

"SOME // Public / ID / 1.0"

many thanks
Peewee

Sorry, I never found any explanation about this parameter.  This is the value given as sample on the module synopsis at CPAN.  I seen other sample where this value is used as it is.  You can also leave it empty ("").

Avatar of PeeweePeewee

ASKER

olaloux,

many thanks for your help here..

cheers
peewee

Free T-shirt

Get a FREE t-shirt when you ask your first question.

We believe in human intelligence. Our moderation policy strictly prohibits the use of LLM content in our Q&A threads.

Web Languages and Standards

Web Languages and Standards

--

Questions

--

Followers

Top Experts

Web development can range from developing the simplest static single page of plain text to the most complex web-based internet applications, electronic businesses, and social network services using a wide variety of languages and standards, including the familiar HTML, JavaScript and jQuery, ASP and ASP.NET, PHP, ColdFusion, CSS, PHP, Flex and Flash, but also the implementation of a broad list of standards including XML, WSDL, SSDL, VoiceXML and many more.