dimanche 2 août 2015

how do i validate xml against dtd using python?

I have a xml file "sample.xml" as:

<?xml version="1.0" encoding="UTF8" ?>
< !DOCTYPE nodedescription SYSTEM "sample.dtd" >
<node_description>
    <target id="windows 32bit">
        <graphics>nvidia_970</graphics>
        <power_plug_type>energenie_eu</power_plug_type>
        <test>unit test</test>
   </target>
   <target id="windows 64bit">
       <graphics>nvidia_870</graphics>
       <power_plug_type>energenie_eu</power_plug_type>
       <test>performance test</test>
   </target>
</node_description>

and respective dtd as "sample.dtd":

<?xml version="1.0" encoding="UTF-8"?>
<!ELEMENT node_description (target)*>
<!ATTLIST target id CDATA #REQUIRED>
<!ELEMENT target (graphics, power_plug_type, test)>
<!ELEMENT graphics (#PCDATA)*>
<!ELEMENT power_plug_type (#PCDATA)*>
<!ELEMENT test (#PCDATA)*>

I want "sample.xml" to get validated against "sample.dtd" by making use of python script. How will i achieve this? kindly help.

Aucun commentaire:

Enregistrer un commentaire