V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
cheerzeng
V2EX  ›  Python

Preserving Tag Order With Python's XMLTODICT?

  •  
  •   cheerzeng · 2016-06-02 11:49:02 +08:00 · 2615 次点击
    这是一个创建于 3081 天前的主题,其中的信息可能已经有所发展或是发生改变。
    问题跟这个帖子一样,除了 sf 的答案,有没有更简单的?
    https://www.experts-exchange.com/questions/28459856/Preserving-Tag-Order-With-Python's-XMLTODICT.html

    I recently developed something that would change attributes, calculate word counts, and change spellings for certain words based on a set of rules defined in Python. I originally made the service by taking the XML file and turning it into a Python dictionary and then sorting through it that way. I used the xmltodict Python library, and I got the correct results without too much coding.

    <root>
    <Content>
    <Marker>NOISE</Marker>
    <Fragment>Some text is here</Fragment>
    <Marker>INTERRUPTION></Marker>
    </Content>
    </root>

    The result is a dictionary structured as follows:

    Content {
    => Marker = array(["NOISE", "INTERRUPTION"])
    => Fragment = "Some text is here"
    }


    The specification for the XML changed and I am now realising the limitations of my original solution. Let me explain:




    http://stackoverflow.com/questions/34636273/python-xmltodict-how-to-preserve-xml-element-order
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2752 人在线   最高记录 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 14:54 · PVG 22:54 · LAX 06:54 · JFK 09:54
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.