Python XML Module

Source: Internet
Author: User

XML module

Create your own XML document

ImportXml.etree.cElementTree as Etnew_xml= ET. Element ("personinfolist") Personinfo= ET. Subelement (New_xml,"Personinfo", attrib={"enrolled":"Yes"}) name= ET. Subelement (Personinfo,"name") Name.text="Alex Li" Age= ET. Subelement (Personinfo," Age", attrib={"checked":"No"}) Sex= ET. Subelement (Personinfo,"Sex") Age.text=' About'et=ET. ElementTree (New_xml) et.write ("Test1.xml", encoding="Utf-8", xml_declaration=True) Et.dump (New_xml)

Results

<?XML version= ' 1.0 ' encoding= ' utf-8 '?><personinfolist>    <Personinfoenrolled= "Yes">      <name>Alex Li</name>      < Agechecked= "No">56</ Age><Sex/>    </Personinfo></personinfolist>

Note: The XML module needs to be enabled for creation.

Note: The Et.element creation name is required for creation

Note: Et.subelement creates additional values.

Note: Et.elementtree generates a Document object.

Note: Et.dump print generation format.

Python XML Module

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.