2323"""
2424
2525class DocumentType (object ):
26- def __init__ (self , name , publicId = None , systemId = None ):
26+ def __init__ (self , name , publicId , systemId ):
2727 self .name = name
2828 if name != name .lower ():
29- warnings .warn ("lxml does not preserve doctype case" , DataLossWarning )
29+ warnings .warn ("lxml does not preserve doctype case" , DataLossWarning )
3030 self .publicId = publicId
3131 self .systemId = systemId
3232
@@ -56,7 +56,7 @@ def serializeElement(element, indent=0):
5656 element .docinfo .system_url ):
5757 dtd_str = "<!DOCTYPE %s>" % element .docinfo .root_name
5858 else :
59- dtd_str = """<!DOCTYPE %s PUBLIC "%s" "%s">""" % (
59+ dtd_str = """<!DOCTYPE %s "%s" "%s">""" % (
6060 element .docinfo .root_name ,
6161 element .docinfo .public_id ,
6262 element .docinfo .system_url )
@@ -181,9 +181,7 @@ def getFragment(self):
181181 def insertDoctype (self , name , publicId , systemId ):
182182 if not name :
183183 warnings .warn ("lxml cannot represent null doctype" , DataLossWarning )
184- doctype = self .doctypeClass (name )
185- doctype .publicId = publicId
186- doctype .systemId = systemId
184+ doctype = self .doctypeClass (name , publicId , systemId )
187185 self .doctype = doctype
188186
189187 def insertCommentInitial (self , data , parent = None ):
@@ -196,7 +194,7 @@ def insertRoot(self, name):
196194 #Therefore we need to use the built-in parser to create our iniial
197195 #tree, after which we can add elements like normal
198196 docStr = ""
199- if self .doctype :
197+ if self .doctype and self . doctype . name :
200198 docStr += "<!DOCTYPE %s" % self .doctype .name
201199 if self .doctype .publicId is not None or self .doctype .systemId is not None :
202200 docStr += ' PUBLIC "%s" "%s"' % (self .doctype .publicId or "" ,
0 commit comments