内容简介:# cat HKEX-EPS_20180830_003249795.xml<?xml version="1.0" encoding="UTF-8"?
1. 问题描述
属性无序问题和 xml 声明不是单独一行
# cat HKEX-EPS_20180830_003249795.xml
>1400
达到效果:
cat HKEX-EPS_20180830_003249795.xml
>
1400
2 操作步骤
2.1 环境说明
系统自带 python2.6.6 升级为 python2.7.10
如果没有升级 python2.7 ,
>>> import sys
>>> sys.path
路径为 /usr/lib64/python2.6/xml/dom
使用的模块是
import xml.dom.minidom
2.2 换行处理
# cd /usr/local/lib/python2.7/xml/dom/
原始配置
def writexml(self, writer, indent="", addindent="", newl="",
encoding = None):
if encoding is None:
writer.write(''+ newl )
else:
writer.write('%s' % (encoding, newl ))
for node in self.childNodes:
node.writexml(writer, indent, addindent, newl)
修改配置
def writexml(self, writer, indent="", addindent="", newl="",
encoding = None):
if encoding is None:
writer.write(''+ '\n' )
else:
writer.write('%s' % (encoding, '\n' ))
for node in self.childNodes:
node.writexml(writer, indent, addindent, newl)
2.3 属性有序处理
原始配置
def __init__(self, tagName, namespaceURI=EMPTY_NAMESPACE, prefix=None,
localName=None):
self.tagName = self.nodeName = tagName
self.prefix = prefix
self.namespaceURI = namespaceURI
self.childNodes = NodeList()
self._attrs = {} # attributes are double-indexed:
self._attrsNS = {} # tagName -> Attribute
# URI,localName -> Attribute
# in the future: consider lazy generation
# of attribute objects this is too tricky
# for now because of headaches with
# namespaces.
......
def writexml(self, writer, indent="", addindent="", newl=""):
# indent = current indentation
# addindent = indentation to add to higher levels
# newl = newline string
writer.write(indent+"<" + self.tagName)
attrs = self._get_attributes()
a_names = attrs.keys()
a_names.sort()
修改配置:
def __init__(self, tagName, namespaceURI=EMPTY_NAMESPACE, prefix=None,
localName=None):
self.tagName = self.nodeName = tagName
self.prefix = prefix
self.namespaceURI = namespaceURI
self.childNodes = NodeList()
#self._attrs = {} # attributes are double-indexed:
self._attrs = OrderedDict() # attributes are double-indexed:
self._attrsNS = {} # tagName -> Attribute
# URI,localName -> Attribute
# in the future: consider lazy generation
# of attribute objects this is too tricky
# for now because of headaches with
# namespaces.
......
def writexml(self, writer, indent="", addindent="", newl=""):
# indent = current indentation
# addindent = indentation to add to higher levels
# newl = newline string
writer.write(indent+"<" + self.tagName)
attrs = self._get_attributes()
a_names = attrs.keys()
#a_names.sort()
3. 总结
亲测可用
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 如何强制dicts无序(用于测试)?
- 基于Redis无序集合实现禁止多端登录
- 引起相变的无序结构域(IDRs)怎么预测?跟踪热点,提升文章档次!
- 激辩“AI+教育”的无序狂奔:暴露在“人脸识别”下的孩子们
- 一行一行源码分析清楚AbstractQueuedSynchronizer
- 一行一行手敲webpack4配置
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
无线:网络文化中激进的经验主义
[英] 阿德里安·麦肯齐 / 张帆 / 上海译文出版社 / 2018-9
本书研究了无线是如何成为当代人类经验的主角的。从路由器、智能电话、电子书、城市到在线工作、服务协议、玩具以及国家等各个方面,人们已经感觉到了无线技术所引发的变革。本书作者援引一个世纪之前的哲学技术来分析当代最前沿的后网络时代的人类状况。基于威廉•詹姆斯的实用主义哲学相关的彻底经验主义,作者提出了把失序的无线网络世界与人们的感知匹配起来的新方式。一起来看看 《无线:网络文化中激进的经验主义》 这本书的介绍吧!