easy-xml


Nameeasy-xml JSON
Version 0.6.1 PyPI version JSON
download
home_pagehttps://github.com/darkfoxprime/python-easy_xml
SummaryEasyXML is a simple object representation of an XML document.
upload_time2024-01-02 04:58:14
maintainer
docs_urlNone
authorJohnson Earls
requires_python
licenseISC
keywords xml
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            EasyXML presents a simplified view of an XML document.

Elements in the XML document, including the root-level document,
are represented by EasyXML objects.  Each EasyXML object has a
`_name` attribute holding the name of the element represented by
the EasyXML object, a dictionary called `_attrs` holding the element's
attributes, and a sequence called `_content` holding the content
of the element.  The `_content` sequence contains strings for the
character data within the element (with whitespace stripped from
the beginning and end), and other EasyXML objects for nested XML
elements.

The content of the EasyXML object can be accessed directly as if it
were a sequence itself.  In addition, the element's attributes
themselves may be accessed by name on the EasyXML object.

For example, the XML fragment ``<zip code="12345">Schenectady,
NY</zip>`` would be returned as an EasyXML object where *name*.``_name``
is ``'zip'``, *name*.``_attrs`` is ``{'code': '12345'}``, *name*.
``_content`` is ``['Schenectady, NY']``, *name*.``code`` is ``'12345'``,
and *name*.``[0]`` is ``'Schenectady, NY'``.

Usage:

::

    # Import the EasyXML class
    from easy_xml import EasyXML

    # Parse the file-like object `stream` into an EasyXML structure.
    xmldoc = EasyXML.parseXML(stream)

    # Find the first ``<hello>`` node in the document.
    # If it exists, record its content in the `hello` variable.
    # If not, record ``world`` in `hello`, and create a new
    # ``<hello>world</hello>`` XML element at the top of the document.

    for element in xmldoc:
        if isinstance(element,EasyXML) and element._name == 'hello':
            hello = ' '.join(element._content)
            break

    if hello is None:
        hello = 'world'
        element = EasyXML('hello', content=[hello])
        xmldoc._content.insert(0, element)

    # Convert the EasyXML structure back into a valid XML document.
    xmlfile = str(xmldoc)

Notes:

* Processing instructions and comments are ignored.
* Only basic entity processing (``&lt;``, ``&gt;``, and ``&amp;``)
  is performed.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/darkfoxprime/python-easy_xml",
    "name": "easy-xml",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "xml",
    "author": "Johnson Earls",
    "author_email": "johnson.earls@oracle.com",
    "download_url": "https://files.pythonhosted.org/packages/d6/48/12e98a75d1c204a836bb5defe0f294f596901e41e88b99576a2aca47ec15/easy_xml-0.6.1.tar.gz",
    "platform": null,
    "description": "EasyXML presents a simplified view of an XML document.\r\n\r\nElements in the XML document, including the root-level document,\r\nare represented by EasyXML objects.  Each EasyXML object has a\r\n`_name` attribute holding the name of the element represented by\r\nthe EasyXML object, a dictionary called `_attrs` holding the element's\r\nattributes, and a sequence called `_content` holding the content\r\nof the element.  The `_content` sequence contains strings for the\r\ncharacter data within the element (with whitespace stripped from\r\nthe beginning and end), and other EasyXML objects for nested XML\r\nelements.\r\n\r\nThe content of the EasyXML object can be accessed directly as if it\r\nwere a sequence itself.  In addition, the element's attributes\r\nthemselves may be accessed by name on the EasyXML object.\r\n\r\nFor example, the XML fragment ``<zip code=\"12345\">Schenectady,\r\nNY</zip>`` would be returned as an EasyXML object where *name*.``_name``\r\nis ``'zip'``, *name*.``_attrs`` is ``{'code': '12345'}``, *name*.\r\n``_content`` is ``['Schenectady, NY']``, *name*.``code`` is ``'12345'``,\r\nand *name*.``[0]`` is ``'Schenectady, NY'``.\r\n\r\nUsage:\r\n\r\n::\r\n\r\n    # Import the EasyXML class\r\n    from easy_xml import EasyXML\r\n\r\n    # Parse the file-like object `stream` into an EasyXML structure.\r\n    xmldoc = EasyXML.parseXML(stream)\r\n\r\n    # Find the first ``<hello>`` node in the document.\r\n    # If it exists, record its content in the `hello` variable.\r\n    # If not, record ``world`` in `hello`, and create a new\r\n    # ``<hello>world</hello>`` XML element at the top of the document.\r\n\r\n    for element in xmldoc:\r\n        if isinstance(element,EasyXML) and element._name == 'hello':\r\n            hello = ' '.join(element._content)\r\n            break\r\n\r\n    if hello is None:\r\n        hello = 'world'\r\n        element = EasyXML('hello', content=[hello])\r\n        xmldoc._content.insert(0, element)\r\n\r\n    # Convert the EasyXML structure back into a valid XML document.\r\n    xmlfile = str(xmldoc)\r\n\r\nNotes:\r\n\r\n* Processing instructions and comments are ignored.\r\n* Only basic entity processing (``&lt;``, ``&gt;``, and ``&amp;``)\r\n  is performed.\r\n",
    "bugtrack_url": null,
    "license": "ISC",
    "summary": "EasyXML is a simple object representation of an XML document.",
    "version": "0.6.1",
    "project_urls": {
        "Homepage": "https://github.com/darkfoxprime/python-easy_xml"
    },
    "split_keywords": [
        "xml"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "be268adcc3d3ac2c1f8d6cb1ebe4b3fa00e42c3449164e3553654e39920b514d",
                "md5": "ea0f511af18c8e7386c3717a4fc9bb4d",
                "sha256": "6d735785324e4f0b62fa1fa5e3ce3ce5c423f07d1d0f3751eefca522cf726cdd"
            },
            "downloads": -1,
            "filename": "easy_xml-0.6.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "ea0f511af18c8e7386c3717a4fc9bb4d",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 6648,
            "upload_time": "2024-01-02T04:58:12",
            "upload_time_iso_8601": "2024-01-02T04:58:12.894343Z",
            "url": "https://files.pythonhosted.org/packages/be/26/8adcc3d3ac2c1f8d6cb1ebe4b3fa00e42c3449164e3553654e39920b514d/easy_xml-0.6.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "d64812e98a75d1c204a836bb5defe0f294f596901e41e88b99576a2aca47ec15",
                "md5": "17d6f919c12c136440c0994aec1323b9",
                "sha256": "4c369110e281f577893ca89c420d294f7c9551d904a9fc2b9a53c60aa17c2404"
            },
            "downloads": -1,
            "filename": "easy_xml-0.6.1.tar.gz",
            "has_sig": false,
            "md5_digest": "17d6f919c12c136440c0994aec1323b9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9216,
            "upload_time": "2024-01-02T04:58:14",
            "upload_time_iso_8601": "2024-01-02T04:58:14.280190Z",
            "url": "https://files.pythonhosted.org/packages/d6/48/12e98a75d1c204a836bb5defe0f294f596901e41e88b99576a2aca47ec15/easy_xml-0.6.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-02 04:58:14",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "darkfoxprime",
    "github_project": "python-easy_xml",
    "github_not_found": true,
    "lcname": "easy-xml"
}
        
Elapsed time: 0.17279s