I am making a Python script that generates XML + DTD files passed as inputs, but it fails because the DTD cannot be verified while I do not see any problems βvisuallyβ.
Here is my code:
DTD = 'scenario.dtd' def OpenXML(xmlDesc): dtd = libxml2.parseDTD(None,DTD) ctxt = libxml2.newValidCtxt() doc = libxml2.parseDoc(xmlDesc) frags = doc.xpathEval('/scenario/config_script/param/*') for frag in frags: frag.unlinkNode()
So, here is the DTD, and XML String I am passed as a parameter (xmlDesc)
Original DTD (.dtd script)
<!ELEMENT scenario (name, description, config_script*)> <!ELEMENT name (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT config_script (param)> <!ELEMENT param ANY> <!ATTLIST scenario target (win32|win64|linux32|linux64) "win32"> <!ATTLIST config_script name CDATA #REQUIRED> <!ATTLIST config_script repository CDATA #REQUIRED>
Dtd variable value (1st line of the function)
<!DOCTYPE none SYSTEM "scenario.dtd" [ <!ELEMENT scenario (name, description, config_script*)> <!ELEMENT name (#PCDATA)> <!ELEMENT description (#PCDATA)> <!ELEMENT config_script (param)> <!ELEMENT param ANY> <!ATTLIST scenario target (win32|win64|linux32|linux64) "win32"> <!ATTLIST config_script name CDATA #REQUIRED> <!ATTLIST config_script repository CDATA #REQUIRED> ]>
xml (everything for me on one line, but for reading I break lines)
<config_scripts> <script name="reset" repository="config_os"> <param> <user> <name/> <full_name/> <password/> <groups/> </user> </param> </script> </config_scripts>
And I finally get this error -> ERROR : DTD Validation failed !
In addition, I can read this in the console:
No declaration for element config_script No declaration for element script No declaration for attribute name of element script No declaration for attribute repository of element script No declaration for element user No declaration for element full_name No declaration for element password No declaration for element groups
But as far as I know, they are announced ... Or maybe it is because I left all the allowances empty?
Any ideas?
Best regards and thank you