Greetings. I want to append instructions for XSLT without converting an XML object to string.
Is there a solution for doing so, yet? This code: import xml.etree.ElementTree as ET e_feed = ET.Element("feed") e_feed.set("xmlns", "http://www.w3.org/2005/Atom") xslt_reference = ET.ProcessingInstruction( "xml-stylesheet", "type=\"text/xml\" href=\"stylesheet.xsl\"") e_feed.insert(0, xslt_reference) Would yield this result: <?xml version='1.0' encoding='utf-8'?> <feed xmlns="http://www.w3.org/2005/Atom"> <?xml-stylesheet type="text/xml" href="stylesheet.xsl"?> </feed> Yet, the intended resukt is: <?xml version='1.0' encoding='utf-8'?> <?xml-stylesheet type="text/xml" href="stylesheet.xsl"?> <feed xmlns="http://www.w3.org/2005/Atom"> </feed> That is, the instruction should be above element "feed". Please advise. On Fri, 31 Jan 2025 18:02:06 -0000 Neil Donaldson via lxml - The Python XML Toolkit <lxml@python.org> wrote: > Just configure the output encoding explicitly or force the XML > declaration to be written. ET.ElementTree(e_feed).write("chathappy.atom", encoding="unicode", xml_declaration=True) Thank you. _______________________________________________ lxml - The Python XML Toolkit mailing list -- lxml@python.org To unsubscribe send an email to lxml-le...@python.org https://mail.python.org/mailman3//lists/lxml.python.org Member address: arch...@mail-archive.com