Validating XML with a DTD and python.

Below is a way to validate an XML file using python and an external DTD.

Are there any other ways to do XML DTD validation with python?

A DTD is one way of specifying how an XML should be formed - a schema for XML documents.


from xml.parsers.xmlproc import xmlproc
from xml.parsers.xmlproc import xmlval
from xml.parsers.xmlproc import xmldtd

def validate_xml(xml_filename, dtd_filename):
"""Validate a given XML file with a given external DTD.
If the XML file is not valid, an exception will be
printed with an error message.
"""
dtd = xmldtd.load_dtd(dtd_filename)
parser = xmlproc.XMLProcessor()
parser.set_application(xmlval.ValidatingApp(dtd, parser))
parser.dtd = dtd
parser.ent = dtd
parser.parse_resource(xml_filename)


if __name__ == "__main__":
import sys
xml_filename, dtd_filename = sys.argv[1], sys.argv[2]
validate_xml(xml_filename, dtd_filename)






Melbourne Web Developer Written by a Melbourne web developer. Available for your projects - php, mysql, e commerce, javascript, CMS, css, flash, actionscript, python, games, postgresql, xml.

Comments

Unknown said…
Have a look at lxml: it's a pythonic binding for libxml/libxslt. It uses the elementtree api but offers additional features over the etree package you find in the standard lib, including validation (with dtd, xsd and relax ng)
Bablu said…
Hi,
I validate my code with schema , getting errors . So I tried DTD still some unresolved error. this is my code "URL: http://rafb.net/p/VzmEsE80.html"

advanced thanks,
pradeep
ROSHIYA said…
Roku connects to your TV utilizing Roku.com/link an HDMI link, associated from your TV to the Roku gadget. Roku interfaces with the web by means of a wired or remote association with your home system. Roku works by downloading video from Roku.com/link the web, you at that point watch on your TV. The video isn't spared as it's viewed while Roku downloads or "streams" the video. Applications or "stations" are programs you load onto your Roku gadget that give you different films and TV appears. This works a lot of like introducing applications on a cell phone or tablet. Roku enables you to choose what gives you Roku.com/link need to watch, and when you need to watch them. It resembles sitting in front of the TV as though everything is on-request. Since Roku extraordinarily extends your on-request alternatives, you may even need one to enhance your link membership as opposed to supplanting it. I'll really expound on that later in the guide. .

office it the pile of office office.com/setup gadgets to make your working smooth and effective.visit: to downloaded in your PC with the smart help.Endeavor which is amazingly office.com/setup easy to present, download and recoup. Usage of it is moreover fundamental and the customer can pick up capability with the use of it adequately. Online Support&help elective is in like manner open in all application which gives a minute guideline.Microsoft Office is an application office.com/setup software. It is used in most of the businesses and organizations Install office setup on your Pc's to get best advantage of it. mostly used tasks are ms-word, Ms-excel and Ms-powerpoint.
ROSHIYA said…
Microsoft Office Setup is the office.com/setup complete bundle of Microsoft programs as it takes to the a variety of jobs, servers, and affiliations like PowerPoint, Excel, Word, Outlook, Publisher, OneNote, and Access.office setup is the best programming which is broadly utilized in globe .It is a dazzling association that causes you release your best contemplations, complete things, and stay related on the go.for more subtleties visit: today.Be more innovative and accomplish office.com/setup what is important with Outlook, OneDrive, Word, Excel, PowerPoint, OneNote, SharePoint, Microsoft Teams, Yammer, and that's only the tip. For more details go through the links:Microsoft Office Setup is the full office.com/setup suite of Microsoft utmost programming that joins a mix of livelihoods, affiliations, and server like Excel, PowerPoint, Word, OneNote, Publisher, and Access. Get to know more details visit the links:

Microsoft office setup isn't office.com/setup open for Windows contraption, yet in like a way for Macs, and phones. The Microsoft Office 2016 suite looks as strong and major as its harbingers and a marvelous arrangement has changed. Having any doubts visit the links:Microsoft Office is an office office.com/setup suite that wires a degree of master report and database applications, servers and affiliations. This wide range joins perpetual indisputable and obvious tasks like Word, Excel, PowerPoint, Outlook, Microsoft Access, OneNote, other than applications, for instance, Microsoft Publisher, Microsoft Project, Microsoft Visio, Skype for Business, and SharePoint Designer. Have a trial of it... and to setup it in your pc Do visit : Microsoft Office A Series Of office.com/setup Subscription-Based Services Which Includes Client Software As Well As Server Software. It Is Generally Offered As A Component Of The Microsoft Office Product Line Which Can Be Installed By Office setup. Any question regarding this visit our site:

ROSHIYA said…
Download office 365 with office.com/setup our assistance group without completing any work independent from anyone else.In case customer needs to use the office.com/setup Office setup on the web, by then open the web program you are using on your structure and visit office setup today.Get your Office Setup Installed office.com/setup with the help of the best help team. You may install the complete office 365 package without any complicated work.

Ms Office suite offers a wide office.com/setup selection of products but to access a licensed version, you must have Office product key.After you exceed the free trial period, it becomes mandatory to purchase an Office setup product key. Get office setup hereoffice setup is the best software office.com/setup which is widely used in globe .It is a powerful service that helps you unleash your best ideas , get things done, and stay connected on the go.for more details visit:Well ordered guide how to download,office.com/setup install and initiate your MS Office 365, Office 2016,etc. on any gadget. In the event that you have discover any issue in making your Office account, at that point visit this site certainly causes you.
ROSHIYA said…
All purchasers worldwide have been webroot.com/safe Webroot SecureAnywhere Antivirus is more than antivirus programming. It is antimalware. It stops the infections and worms that exist so as to contaminate webroot.com/safe different PCs, yet it additionally ensures you during web surfing sessions by blocking destructive sites.casualties of cybercrime. Webroot offers total insurance from infections and data fraud for every one of your gadgets, without backing you off.

Mcafee.com activate- Find the easy way to mcafee.com/activate download, install and activate McAfee Antivirus, type the 25-digit product key at mcafee.comactivate. Protect your PC from virus, spam, spyware, and malware. McAfee provides the latest antivirus software, spyware removal and internet security for your home or home office.Present mcafee thing with mcafee.com/activate no issue. We give best foundation advantage. visit today.Activate mcafee antivirus with the mcafee.com/activate highly professional tech team and get rid of antivirus from computer click the link for more details.
ROSHIYA said…
mcafee antivirus is broadly mcafee.com/activate utilized antivirus recognizes and kill PC infection, the infected mail ,the malware programs,and enables your framework to free of infection and other malware is a serious every day challenge.McAfee Activate! you can start mcafee.com/activate incitation with enter thing code/key at and visit for more nuances.It is unsurpassed best defensive mcafee.com/activate antivirus and against spyware .It is ongoing security innovation and it is more secure.

mcafee antivirus is widely mcafee.com/activate used aantivirus helps to detect and neutralize computer virus, the mail worms,the trojan programs,and also helps your system free of virus and other malware is quite a daily challenge. for more details visit today.mcafee antivirus is broadly mcafee.com/activate utilized aantivirus distinguishes and kill PC infection, the mail worms,the trojan programs,and likewise helps ]- your framework free of infection and other malware is a significant every day challenge. for more subtleties visit today.mcafee antivirus is widely used mcafee.com/activate antivirus helps to detect and neutralize computer virus, the mail worms,the trojan programs,and also helps your system free of virus and other malware is quite a daily challenge.to uninstall the mcafee, or for more details visit: mcafee uninstall.
ROSHIYA said…
McAfee thing in citation is an mcafee.com/activate antivirus program. this program secure your PC with tainting so you can display it. to see significantly more please visit our site .It is unequaled best defensive mcafee.com/activate antivirus and hostile to spyware .It is continuous insurance innovation and it is more secure , quicker and more total than any time in recent memory before.if need to introduce it at that point visit our site. McAfee is committed to your mcafee.com/activate security and provides an assortment of free McAfee tools to aid in your security protection. Simply select a tool and download it for free.

Mcafee login To Activate your mcafee.com/activate 25 Digit Product Key Login Mcafee on your PC with ... You can without much of a stretch sign into your mcafee my account and activate the product visit here.Mcafee.com/activate- Find the easy way to download, install and activate McAfee Antivirus, type the 25-digit product key at mcafee.comactivate. Protect your PC from virus, spam, spyware, and malware. McAfee provides the latest antivirus software, spyware removal and internet security for your home or home office.Present mcafee thing with no issue. mcafee.com/activate We give best foundation advantage. visit today.Activate mcafee antivirus with mcafee.com/activate the highly professional tech team and get rid of antivirus from computer click the link for more details.
ROSHIYA said…
McAfee thing in citation is mcafee.com/activate an antivirus program. this program secure your PC with tainting so you can display it. to see significantly more please visit our site .It is unequaled best defensive mcafee.com/activate antivirus and hostile to spyware .It is continuous insurance innovation and it is more secure , quicker and more total than any time in recent memory before.if need to introduce it at that point visit our site. McAfee is committed to your mcafee.com/activate security and provides an assortment of free McAfee tools to aid in your security protection. Simply select a tool and download it for free.

Mcafee.com activate- mcafee.com/activate Find the easy way to download, install and activate McAfee Antivirus, type the 25-digit product key at mcafee.comactivate. Protect your PC from virus, spam, spyware, and malware. McAfee provides the latest antivirus software, spyware removal and internet security for your home or home office.Present mcafee thing with no mcafee.com/activate issue. We give best foundation advantage. visit today.Activate mcafee antivirus mcafee.com/activate with the highly professional tech team and get rid of antivirus from computer click the link for more details.
ROSHIYA said…
McAfee thing in citation is an antivirus mcafee.com/activate program. this program secure your PC with tainting so you can display it. to see significantly more please visit our site .It is unequaled best defensive mcafee.com/activate antivirus and hostile to spyware .It is continuous insurance innovation and it is more secure , quicker and more total than any time in recent memory before.if need to introduce it at that point visit our site. McAfee is committed to your security and mcafee.com/activate provides an assortment of free McAfee tools to aid in your security protection. Simply select a tool and download it for free.

Mcafee.com/activate- Find the easy mcafee.com/activate way to download, install and activate McAfee Antivirus, type the 25-digit product key at mcafee.comactivate. Protect your PC from virus, spam, spyware, and malware. McAfee provides the latest antivirus software, spyware removal and internet security for your home or home office.Present mcafee thing with no issue. mcafee.com/activate We give best foundation advantage. visit today.Activate mcafee antivirus with mcafee.com/activate the highly professional tech team and get rid of antivirus from computer click the link for more details.
ROSHIYA said…
mcafee antivirus is broadly mcafee.com/activate utilized antivirus recognizes and kill PC infection, the infected mail ,the malware programs,and enables your framework to free of infection and other malware is a serious every day challenge.McAfee Activate! you can start mcafee.com/activate incitation with enter thing code/key at and visit for more nuances.It is unsurpassed best defensive mcafee.com/activate antivirus and against spyware .It is ongoing security innovation and it is more secure.

mcafee antivirus is mcafee.com/activate widely used aantivirus helps to detect and neutralize computer virus, the mail worms,the trojan programs,and also helps your system free of virus and other malware is quite a daily challenge. for more details visit today.mcafee antivirus is broadly mcafee.com/activate utilized aantivirus distinguishes and kill PC infection, the mail worms,the trojan programs,and likewise helps ]- your framework free of infection and other malware is a significant every day challenge. for more subtleties visit today.mcafee antivirus is widely used mcafee.com/activate antivirus helps to detect and neutralize computer virus, the mail worms,the trojan programs,and also helps your system free of virus and other malware is quite a daily challenge.to uninstall the mcafee, or for more details visit: mcafee uninstall.
ROSHIYA said…
McAfee thing in citation is an mcafee.com/activate antivirus program. this program secure your PC with tainting so you can display it. to see significantly more please visit our site .
ROSHIYA said…

All you have to do is to amazon.com/mytv activate your Amazon Prime Video on amazon.com mytv using the activation code you retrieve.amazon Payment Products. Amazon amazon.com/mytv Rewards Visa Signature Cards; Amazon.com Store Card; Amazon Business Card; Amazon Business Line of Credit; Shop with Points; Now enter the activation or amazon.com/mytv verification code that appears on your tv display. Amazon Prime Video is one of the most amazing and interesting platforms to watch.

Amazon Instant Video application amazon.com/mytv on your LG TV or Blu-ray Player and then Prime Instant Video to start watching.Amazon.com mytv is a amazon.com/mytv registration portal of Amazon Prime from which members can watch thousands of movies and TV shows The instant video amazon.com/mytv service can only be watched after registering your device with a simple subscription code.
ROSHIYA said…
Norton Security Real-time norton.com/setup insurance against existing and developing malware including ransomware and infections.Norton Security ensures your norton.com/setup gadgets and the data on them, Norton Secure VPN encodes the information you send and get when utilizing open Wi-Fi.norton internet security is widely norton.com/setup used antivirus provides the easiest to use and most intutive protection for your computer and your mobiles .install it and forget about viruses,spyware,root-kits -, hackers.for more details visit today.

norton web security is generally norton.com/setup utilized antivirus gives the least demanding to utilize and most intutive assurance for your PC and your mobiles .introduce it and disregard viruses,spyware,root-units - , hackers.for more subtleties visit.Antivirus is the need of PCs that norton.com/setup makes them ailment free and we are going to give you full help to get the best antivirus presented in your PCs and workstations. Download norton antivirus store up with us today.norton web security is commonly norton.com/setup used antivirus gives the least requesting to use and most intutive affirmation for your PC and your mobiles .present it and negligence viruses,spyware,root-units - , hackers.for more nuances visit.
ROSHIYA said…
Antivirus is the need of norton.com/setup PCs that makes them sickness free and we are going to give you full help to get the best antivirus exhibited in your PCs and workstations. Download norton antivirus store up with us today.norton web security is generally norton.com/setup utilized antivirus gives the least demanding to utilize and most intutive assurance for your PC and your mobiles.Install the norton.com/setup on your Android gadget and disregard viruses,spyware,root-units, programmers.norton web security is broadly norton.com/setup utilized antivirus gives the least demanding to utilize and most intutive insurance for your PC and your mobiles .introduce it and disregard viruses,spyware,root-units, hackers.for more subtleties visit today.

norton web security is ordinarily norton.com/setup utilized antivirus gives the least asking for to utilize and most intutive certification for your PC and your mobiles .present it and carelessness viruses,spyware,root-units - , hackers.for more subtleties visit:Antivirus is the need of PCs that norton.com/setup makes them ailment free and we are going to give you full help to get the best antivirus showed in your PCs and workstations. Download norton antivirus store up with us today.norton web security is regularly norton.com/setup utilized antivirus gives the least asking for to utilize and most intutive confirmation for your PC and your mobiles .present it and carelessness viruses,spyware,root-units - , hackers.for more subtleties visit:
ROSHIYA said…
To activate the Xfinity xfinity.com/authorize device and get high-speed internet services. website that is Xfinity xfinity.com/authorize authorize and Explore best deals online for Internet, Video and Mobile services. Xfinity is a platform which xfinity.com/authorize will keep you entertained and offers HD content at a very exciting price. Here you can stream any content online.

Xfinity. Let's activate your device. xfinity.com/authorize Enter your activation code: Access on Roku and smart TV's will be available once your Xfinity products have been set up in your home.Enjoy and manage TV, xfinity.com/authorize high-speed Internet, phone, and home security services that work seamlessly together Xfinity services are xfinity.com/authorize cancelled during the agreement term. Kit offer for kit serviceable locations only.

Popular posts from this blog

Draft 3 of, ^Let's write a unit test!^

Is PostgreSQL good enough?

post modern C tooling - draft 6