{ "info": { "author": "Erez Bibi", "author_email": "erezbibi@users.sourceforge.net", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: Public Domain", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Text Processing :: Markup :: XML", "Topic :: Utilities" ], "description": "Help module to parse a simple XML buffer and store it as a read-only (mostly)\ndictionary-type object (MyXml). This dictionary can hold other dictionaries,\nnodes-lists, or leaf nodes. Access to the nodes is by using attributes.\n\n>>> xml = parse(\"Val\")\n>>> xml.Foo.Bar == \"Val\"\nTrue\n>>> xml.Foo.Bar\nVal\n\nI don't like to use the built in Python DOM parsers for simple XML data, but\nthis module is good only for simple XML! No name-spaces, CDATA and other fancy\nfeatures are supported.\n\nThere are three factory functions, \"parse\", \"parse_file\" and \"parse_object\".\n\n- parse takes an XML string and builds MyXml object from it.\n\n- parse_file takes a file name reads it and do the same.\n\nBoth functions take an optional list of tags names from the beginning of the\nXML data, to ignore.\n\n- parse_object takes a complex python object (of dictionaries, sequences and\nscalars) and creates MyXml object from it.\n\nIt is possible, but not convenient, to construct an XML trees using this module.\n\nUsage Examples:\n\n>>> xml = parse('''\n... \n... \n...
\n...\t One Two & Three\n...\t \n...\t\t\n...\t \n...\t \n...\t Bla Bla Bla\n...\t \n...\t No\n... Value\n...
\n... ''')\n\n- An XML node is an attribute of the MyXml object\n\n>>> xml.Main.Text\nOne Two & Three\n\n- And also\n\n>>> xml.Main.Text == \"One Two & Three\"\nTrue\n\n>>> xml.Main.Text.value == \"One Two & Three\"\nTrue\n\nThere is also a way to access a node with \"nd_\" prefix (so we can access\npython reserved words), this will also return EMPY_NODE if the node doesn't\nexists.\n\n>>> xml.nd_Main.nd_Text\nOne Two & Three\n\n- A node can be looked at as a list with one item\n\n>>> xml.Main.Double.Double[0] is xml.Main.Double.Double\nTrue\n\n- Nodes Lists are regular lists\n>>> len(xml.Main.List.Item)\n3\n>>> unicode(xml.Main.List.Item[2])\nu'Bla Bla Bla'\n\n- MyXml object is a dictionary\n\n>>> xml[\"Main\"][\"Text\"] == xml.Main[\"Text\"]\nTrue\n>>> xml.Main.get(\"Text\") == xml[\"Main\"].Text\nTrue\n\n- There is also a very simple XPath-like method\n\n>>> xml.xpath(\"Main/List/Item\")[2]\nBla Bla Bla\n\n- Attributes can be accessed with an \"at_\" prefix\n\n>>> xml.Main.List.Item[1].at_ccc\nu'ab+c'\n\n- Access the attributes dictionary with \"at_dict\"\n\n>>> xml.Main.List.Item[0].at_dict[\"aaa\"]\nu'bbb'\n\n- Every value can be looked at as a number and a boolean\n\n>>> xml.Main.BoolNum.boolean\nFalse\n\n- Also attribute can be looked at as booleans or numbers\n\n>>> xml.Main.BoolNum.at_num.number * 2\n7.0\n>>> xml.xpath(\"Main/BoolNum\").at_bool.boolean\nTrue\n\n- But if the value is not a number or boolean (yes, no, true, false, 1, 0) the\n- return value is None\n\n>>> xml.Main.List.Item[0].at_aaa.number\n\n- \"get\" and \"xpath\" return an empty node by default, so we can still use the\n-\tnumber/boolean attributes.\n\n>>> bool(xml.get(\"foo\").boolean)\nFalse\n\n>>> xml.xpath(\"Main/foo\").number is None\nTrue\n\n- Printing MyXml objects keeps the original order and adds indentation.\n- The indentation is not thread safe though.\n\n>>> print xml.Main.List\n\n \n \n Bla Bla Bla\n\n\n- Constructing MyXml object from a python complex object:\n\n>>> xml = parse_object({\n... \"foo1\": \"bar\",\n... \"foo2\": [\"bar1\", \"bar2\", \"bar3\"],\n... \"foo3\": {\"bar\": \"foo\"},\n... \"foo4\": 5\n... }, \"Main\")\t# \"Main\" is the name of the top most node\n\n>>> xml.xpath(\"Main/foo4\").number\n5\n\n- The names of the nodes that hold a sequence items, are the type name of the\n- sequence (list, tuple, set, generator).\n\n>>> xml.xpath(\"Main/foo2/list\")[1] == \"bar2\"\nTrue\n\n- Finally - not very useful - but you can modify MyXml object\n\n>>> add_returns_self = xml.add(MyNode(\"bar5\", \"foo5\"))\t# MyNode(value, name)\n>>> xml.foo5.at_dict[\"attr\"] = \"attr value\"\n>>> xml.xpath(\"Main/foo5\").at_attr == \"attr value\"\nTrue\n\nOne can also use the other built in dictionary and list methods, but this is not\nrecommended\n\n>>> xml\t\t# Here the order is not preserved because of the python dictionary\n
\n 5\n bar\n \n bar1\n bar2\n bar3\n \n \n foo\n \n bar5\n
\n\nPlease note that this module is not efficient in parsing large XML buffers. It\nuses string slicing heavily.\n\nErez Bibi\n\nPlease send comments and questions to\nerezbibi AT users DOT sourceforge DOT net", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "Simple XML Parser", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "my_xml", "package_url": "https://pypi.org/project/my_xml/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/my_xml/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/my_xml/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "Easy to use parser for simple XML", "version": "0.1.2" }, "last_serial": 795136, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "e693fd8ba797ce249fd40f3ea6d9043e", "sha256": "a52ced861475b3003a25b2564e7ef44b8c0a89da52d8213835e0b24d814e4495" }, "downloads": -1, "filename": "my_xml-0.1.0.tar.gz", "has_sig": false, "md5_digest": "e693fd8ba797ce249fd40f3ea6d9043e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6976, "upload_time": "2010-10-02T09:57:18", "url": "https://files.pythonhosted.org/packages/b1/0a/8290c6318fcb0998c03dd4e8b4d7a0e2418d52731c7ba966f5ba986c55a9/my_xml-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "89de55d5369ed3e1eaa3f4188dd658e9", "sha256": "265a50c3bbe2bb065b654326831b94a555661917098f4800721c8c13e3494ef6" }, "downloads": -1, "filename": "my_xml-0.1.1.zip", "has_sig": false, "md5_digest": "89de55d5369ed3e1eaa3f4188dd658e9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12656, "upload_time": "2010-10-04T14:27:20", "url": "https://files.pythonhosted.org/packages/dd/39/27d72b2487b68caf3088c837c8c3d6884b53a38928d068091f895b0870cb/my_xml-0.1.1.zip" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "31be80e597b936509ea8ec818e5978a2", "sha256": "b4a39222f978d7edfd56f8afcd271c45fb4868c4c99e4fc90ed24beef0f10e0a" }, "downloads": -1, "filename": "my_xml-0.1.2-py2.6.egg", "has_sig": false, "md5_digest": "31be80e597b936509ea8ec818e5978a2", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 18615, "upload_time": "2011-01-17T20:04:02", "url": "https://files.pythonhosted.org/packages/da/4a/af8f314dce12643ebf2951fbf50245cc2590bc23be09d1035b6c417f9fad/my_xml-0.1.2-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "6457ee5170b3b01d084f05aaa904ac6e", "sha256": "929faa7798335a72daf0338678573ab2aaacc7fdf00d922e32b3562eb2bb68b9" }, "downloads": -1, "filename": "my_xml-0.1.2.zip", "has_sig": false, "md5_digest": "6457ee5170b3b01d084f05aaa904ac6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12664, "upload_time": "2011-01-17T20:04:01", "url": "https://files.pythonhosted.org/packages/ed/05/59e46b3729162f0c67ec5cb25c535e434cfa119f4c11ebcd9437e93d6b17/my_xml-0.1.2.zip" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "31be80e597b936509ea8ec818e5978a2", "sha256": "b4a39222f978d7edfd56f8afcd271c45fb4868c4c99e4fc90ed24beef0f10e0a" }, "downloads": -1, "filename": "my_xml-0.1.2-py2.6.egg", "has_sig": false, "md5_digest": "31be80e597b936509ea8ec818e5978a2", "packagetype": "bdist_egg", "python_version": "2.6", "requires_python": null, "size": 18615, "upload_time": "2011-01-17T20:04:02", "url": "https://files.pythonhosted.org/packages/da/4a/af8f314dce12643ebf2951fbf50245cc2590bc23be09d1035b6c417f9fad/my_xml-0.1.2-py2.6.egg" }, { "comment_text": "", "digests": { "md5": "6457ee5170b3b01d084f05aaa904ac6e", "sha256": "929faa7798335a72daf0338678573ab2aaacc7fdf00d922e32b3562eb2bb68b9" }, "downloads": -1, "filename": "my_xml-0.1.2.zip", "has_sig": false, "md5_digest": "6457ee5170b3b01d084f05aaa904ac6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12664, "upload_time": "2011-01-17T20:04:01", "url": "https://files.pythonhosted.org/packages/ed/05/59e46b3729162f0c67ec5cb25c535e434cfa119f4c11ebcd9437e93d6b17/my_xml-0.1.2.zip" } ] }