Python Learning Notes (XML generation)

Source: Internet
Author: User

Thinking about adding some functionality to the frame.

The first thing to think about is generating a test report

This is about what format the file is generated in.

I'll be right here. Generate XML-formatted files

I first learned the following code:

1 #!/usr/bin/env python2 #-*-coding:utf_8-*-3 4  fromXml.domImportMinidom5 6XML =Minidom. Document ()7Xml.appendchild (Xml.createcomment ("Test Report"))8Caselist = Xml.createelement ("caselist")9 xml.appendchild (caselist)Ten  One  A defAdd_xml (newxml): -Case = Xml.createelement (" Case") -Case.setattribute ("ID", newxml["ID"]) the  -  -Name = Xml.createelement ("name") -Name.appendchild (Xml.createtextnode (newxml["name"])) +Code = xml.createelement ("Code") -Code.appendchild ((Xml.createtextnode (newxml["Code"]))) +result = Xml.createelement ("result") AResult.appendchild (Xml.createtextnode (newxml["result"])) atTime = Xml.createelement (" Time") -Time.appendchild (Xml.createtextnode (newxml[" Time"])) -  - case.appendchild (name) - case.appendchild (code) - case.appendchild (Result) in Case.appendchild (Time) -  to Caselist.appendchild (case) +  -  theAdd_xml ({"ID":"1001","name":"login user name is correct, password is correct","Code":" $","result":"Test Pass"," Time":"2016-4-13"}) *filename = File ("Case.xml","W") $ xml.writexml (filename)Panax NotoginsengFilename.close ()

The resulting XML file contents are as follows:

1 <?XML version= "1.0"?>2 3 <!--Test Report -4-<caselist>-< CaseID= "1001"><name>Login user name is correct, password is correct</name><Code>200</Code><result>Test Pass</result>< Time>2016-4-13</ Time></ Case></caselist>

Python Learning Notes (XML generation)

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.