python如何读取xml中的list表,并将其转换成如下VCF格式输出?请给出具体程序,编译成功给分
转换前xml文档格式:<?xmlversion="1.0"encoding="UTF-8"standalone="yes"?><Contacts><Contact><Na...
转换前xml文档格式:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Contacts>
<Contact>
<Name>姓名</Name>
<Starred>-1</Starred>
<PhoneList>
<Phone Type="2">11111111111</Phone>
<Phone Type="2">22222222222</Phone>
<Phone Type="1">33333333333</Phone>
</PhoneList>
<EmailList>
<Email Type="3">电子邮件</Email>
</EmailList>
<PostalAddressList>
<PostalAddress Type="1">地址</PostalAddress>
</PostalAddressList>
<OrganizationList>
<Organization Type="1">公司
<Detail>
<Company>公司</Company>
<JobTitle>职位</JobTitle>
</Detail>
</Organization>
</OrganizationList>
<Note>备注</Note>
<Account value="0">
<Name></Name>
<Type></Type>
</Account>
<GroupList>
<GroupName>分组一</GroupName>
</GroupList>
</Contact>
</Contacts>
转换后VCF文档格式:
BEGIN:VCARD
VERSION:3.0
N:姓名
CATEGORIES:分组一
TEL;CELL:11111111111
TEL;CELL:22222222222
TEL;HOME:33333333333
EMAIL:电子邮件
ADR;HOME:地址
ORG;WORK:公司
NOTE:备注
END:VCARD 展开
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<Contacts>
<Contact>
<Name>姓名</Name>
<Starred>-1</Starred>
<PhoneList>
<Phone Type="2">11111111111</Phone>
<Phone Type="2">22222222222</Phone>
<Phone Type="1">33333333333</Phone>
</PhoneList>
<EmailList>
<Email Type="3">电子邮件</Email>
</EmailList>
<PostalAddressList>
<PostalAddress Type="1">地址</PostalAddress>
</PostalAddressList>
<OrganizationList>
<Organization Type="1">公司
<Detail>
<Company>公司</Company>
<JobTitle>职位</JobTitle>
</Detail>
</Organization>
</OrganizationList>
<Note>备注</Note>
<Account value="0">
<Name></Name>
<Type></Type>
</Account>
<GroupList>
<GroupName>分组一</GroupName>
</GroupList>
</Contact>
</Contacts>
转换后VCF文档格式:
BEGIN:VCARD
VERSION:3.0
N:姓名
CATEGORIES:分组一
TEL;CELL:11111111111
TEL;CELL:22222222222
TEL;HOME:33333333333
EMAIL:电子邮件
ADR;HOME:地址
ORG;WORK:公司
NOTE:备注
END:VCARD 展开
2个回答
2013-02-17 · 知道合伙人软件行家
关注
展开全部
1.可以使用ElementTree模块
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import SubElement
from xml.etree.ElementTree import dump
from xml.etree.ElementTree import Comment
from xml.etree.ElementTree import tostring
2.可以使用BeautifulSoup模块
from xml.etree.ElementTree import ElementTree
from xml.etree.ElementTree import Element
from xml.etree.ElementTree import SubElement
from xml.etree.ElementTree import dump
from xml.etree.ElementTree import Comment
from xml.etree.ElementTree import tostring
2.可以使用BeautifulSoup模块
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询