推荐学习书目
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 · Jun 2, 2016 · 3344 views
    This topic created in 3633 days ago, the information mentioned may be changed or developed.
    问题跟这个帖子一样,除了 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
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5785 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 42ms · UTC 06:25 · PVG 14:25 · LAX 23:25 · JFK 02:25
    ♥ Do have faith in what you're doing.