आप एक डॉक प्रकार के साथ अपने दस्तावेज़ बना सकते हैं के साथ शुरू:
# Adapted from example on http://codespeak.net/lxml/tutorial.html
import lxml.etree as et
import StringIO
s = """<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root SYSTEM "test" [ <!ENTITY tasty "cheese">
<!ENTITY eacute "é"> ]>
<root>
<a>&tasty; soufflé</a>
</root>
"""
tree = et.parse(StringIO.StringIO(s))
print et.tostring(tree, xml_declaration=True, encoding="utf-8")
प्रिंट: क्या आप कुछ एक्सएमएल कि एक के साथ नहीं बनाया गया था करने के लिए एक डॉक प्रकार जोड़ना चाहते हैं
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE root SYSTEM "test" [
<!ENTITY tasty "cheese">
<!ENTITY eacute "é">
]>
<root>
<a>cheese soufflé</a>
</root>
, आप पहली बार वांछित doctype के साथ एक (ऊपर) के रूप में बना सकते हैं, तो यह आपके doctype कम XML प्रतिलिपि:
xml = et.XML("<root><test/><a>whatever</a><end_test/></root>")
root = tree.getroot()
root[:] = xml
root.text, root.tail = xml.text, xml.tail
print et.tostring(tree, xml_declaration=True, encoding="utf-8")
प्रिंट:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE root SYSTEM "test" [
<!ENTITY tasty "cheese">
<!ENTITY eacute "é">
]>
<root><test/><a>whatever</a><end_test/></root>
क्या आप यही देख रहे हैं?
स्रोत
2009-07-08 17:33:40
लिंक पुराना है। –