Python解析XML字符串
来源:互联网 发布:央视影音电视直播软件 编辑:程序博客网 时间:2024/05/21 17:49
- # -*- coding: utf-8 -*-
-
- import xml.sax
- import xml.sax.handler
-
- class XMLHandler(xml.sax.handler.ContentHandler):
- def __init__(self):
- self.buffer = ""
- self.mapping = {}
-
- def startElement(self, name, attributes):
- self.buffer = ""
-
- def characters(self, data):
- self.buffer += data
-
- def endElement(self, name):
- self.mapping[name] = self.buffer
-
- def getDict(self):
- return self.mapping
-
-
- data = '''''<?xml version="1.0" encoding="UTF-8"?><note><to>World</to><from>Linvo</from><heading>Hi</heading><body>Hello World!</body></note>'''
-
- xh = XMLHandler()
- xml.sax.parseString(data, xh)
- ret = xh.getDict()
-
- import pprint
- pprint.pprint(ret)
阅读全文
0 0
- Python解析XML字符串
- Python解析XML字符串
- python解析xml字符串
- Python解析XML字符串
- 解析xml的字符串
- java解析xml字符串
- java解析xml字符串
- jdom 解析xml字符串
- 字符串xml 解析
- DOM 解析字符串XML
- C#解析XML字符串
- 解析xml字符串
- 解析xml字符串2
- DOM解析XML字符串
- 解析xml字符串
- jquery 解析XML字符串
- dom4j解析xml字符串
- DOM4J解析xml字符串
- [三代] 获取BADI对象的两种方法
- AngularJs获取传递参数方法
- cdn 内容发布网络
- 为什么要用implements Serializable
- 第三部分 Calendar函数接口
- Python解析XML字符串
- 网络路由检测
- strcpy的使用
- testng的安装和使用
- get和post模拟发送和数据处理
- Referenced file contains errors (http://www.springframework.org/schema/context/spring-context-3.1.xs
- 个人理解:关于指针数组、数组指针、函数指针、函数指针数组、函数指针数组指针
- GO学习之路(一)Go for win10基本环境的安装(Go 语言下载和安装)
- B-和B+树