2323"""
2424
2525class DocumentType (object ):
26- def __init__ (self ,name ,publicId = None ,systemId = None ):
26+ def __init__ (self ,name ,publicId ,systemId ):
2727self .name = name
2828if name != name .lower ():
29- warnings .warn ("lxml does not preserve doctype case" ,DataLossWarning )
29+ warnings .warn ("lxml does not preserve doctype case" ,DataLossWarning )
3030self .publicId = publicId
3131self .systemId = systemId
3232
@@ -56,7 +56,7 @@ def serializeElement(element, indent=0):
5656element .docinfo .system_url ):
5757dtd_str = "<!DOCTYPE %s>" % element .docinfo .root_name
5858else :
59- dtd_str = """<!DOCTYPE %sPUBLIC "%s" "%s">""" % (
59+ dtd_str = """<!DOCTYPE %s "%s" "%s">""" % (
6060element .docinfo .root_name ,
6161element .docinfo .public_id ,
6262element .docinfo .system_url )
@@ -181,9 +181,7 @@ def getFragment(self):
181181def insertDoctype (self ,name ,publicId ,systemId ):
182182if not name :
183183warnings .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 )
187185self .doctype = doctype
188186
189187def 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
198196docStr = ""
199- if self .doctype :
197+ if self .doctype and self . doctype . name :
200198docStr += "<!DOCTYPE %s" % self .doctype .name
201199if self .doctype .publicId is not None or self .doctype .systemId is not None :
202200docStr += ' PUBLIC "%s" "%s"' % (self .doctype .publicId or "" ,