{
"info": {
"author": "David Shu",
"author_email": "david.shu@126.com",
"bugtrack_url": null,
"classifiers": [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Developers",
"License :: OSI Approved",
"License :: OSI Approved :: MIT License",
"Programming Language :: Python",
"Programming Language :: Python :: 2.7",
"Programming Language :: Python :: 3",
"Topic :: Text Processing",
"Topic :: Text Processing :: Markup",
"Topic :: Text Processing :: Markup :: XML"
],
"description": "What is lxml-mate?\r\n==================\r\n\r\nThe simplest XML-Object mapper for Python powered by lxml. It\u2019s powerful.\r\n\r\nNo class definitions are needed to define structure of your XML document.\r\n\r\nYou can create a brand new xml, or create from string, xml document and handle it in very pythonic way.\r\n\r\nSee source code for more documents.\r\n\r\n\r\n\r\nFeatures\r\n========\r\n\r\n**Intercept AttributeError** when access a non-existent tag in order to access more easily.\r\n\r\nFor exmaple:\r\n\r\n >>> s = '''\r\n ... \r\n ... \r\n ... jack\r\n ... 18\r\n ... \r\n ... \r\n ... peter\r\n ... \r\n ... \r\n >>> '''\r\n \r\nwhen we access the second person's age, lxml.objectify.ObjectifiedElement will raise an AttributeError. **lxml-mate will create an null node instead of raising an exception**.\r\n \r\n**lxml**:\r\n \r\n >>> r = objectify.fromstring( s )\r\n >>> ages = [ ( p.name, p.age ) for p in r.person ] #AttributeError be raised.\r\n >>> r.person[0].else.mother = 'jerry' #AttributeError be raised.\r\n \r\n**lxml-mate**:\r\n \r\n >>> r = ObjectifiedElementProxy( xmlstr = s )\r\n >>> ages = [ ( p.name.pyval, p.age.pyval ) for p in r.person[:] ] #dose work\r\n >>> r.person[0].else.mother = 'jerry' #dose work\r\n\r\n\r\nUsage\r\n=====\r\n\r\ncreate\r\n------\r\n\r\nto create a new xml like::\r\n\r\n \r\n \r\n jack\r\n 18\r\n \r\n \r\n \r\n**lxml**:\r\n\r\n >>> from lxml import objectify, etree\r\n >>> r = objectify.Element('root')\r\n >>> person = objectify.SubElement( r, 'person', attrib={'height':'180cm'} )\r\n >>> name = objectify.SubElement( person, 'name' )\r\n >>> person.name = 'jack'\r\n >>> age = objectify.SubElement( person, 'age' )\r\n >>> person.age = 18\r\n \r\nor use E-factory\r\n \r\n >>> E = objectify.E\r\n >>> E.root( E.person( E.name('jack'), E.age(18), height='180cm' ) )\r\n \r\n**lxml-mate**:\r\n\r\n >>> from lxmlmate import ObjectifiedElementProxy\r\n >>> rm = ObjectifiedElementProxy( rootag='root' )\r\n >>> rm.append( E.person( E.name('jack'), E.age(18), height='180cm' ) )\r\n \r\nor\r\n \r\n >>> rm = ObjectifiedElementProxy( objectifiedElement = E.root( E.person( E.name('jack'), E.age(18), height='180cm', height='180cm' ) ) )\r\n \r\nor\r\n \r\n >>> rm = ObjectifiedElementProxy( rootag='root' )\r\n >>> rm.person.name = 'jack'\r\n >>> rm.person.age = 18\r\n >>> rm.person.attrib[ 'height' ] = '180cm'\r\n \r\n \r\nappend\r\n------\r\n\r\nto append xml snippet like::\r\n \r\n >>>\r\n \r\n peter\r\n 45\r\n \r\n \r\n joe\r\n 25\r\n \r\n \r\n**lxml**:\r\n \r\n >>> r.append( E.person( E.name( 'peter' ), E.age( 45 ) ),\r\n ... E.person( E.name( 'joe' ), E.age( 25 ) )\r\n ... )\r\n >>>\r\n \r\n**lxml-mate**:\r\n \r\n >>> rm.append( E.person( E.name( 'peter' ), E.age( 45 ) ),\r\n ... E.person( E.name( 'joe' ), E.age( 25 ) )\r\n ... )\r\n >>>\r\n\r\nor\r\n \r\n >>> rm.insert( 'person', i=None )( 'name', 'peter' )( 'age', 45 )\r\n >>> rm.insert( 'person', i=None )( 'name', 'joe' )( 'age', 25 )\r\n\r\n \r\nselect\r\n------\r\n \r\n**lxml**:\r\n \r\nto select the last person ( named joe ):\r\n \r\n >>> r.person[-1] #return an ObjectifiedElement instance.\r\n \r\nto find persons named joe:\r\n\r\n >>> r.xpath( '//person[name=\"joe\"]' ) #return ObjectifiedElement instances list\r\n\r\n**lxml-mate**:\r\n \r\n >>> rm.person[-1] #return an ObjectifiedElementProxy instance.\r\n >>> rm.xpath( '//person[name=\"joe\"]' ) #return ObjectifiedElementProxy objects list\r\n \r\n \r\nremove\r\n------\r\n\r\nto remove all persons named joe:\r\n \r\n**lxml**:\r\n \r\n >>> p = r.xpath( '//person[name=\"joe\"]' )\r\n >>> for k in p: r.remove( k )\r\n \r\n**lxml-mate**:\r\n \r\n >>> pm = rm.xpath( '//person[name=\"joe\"]' )\r\n >>> rm.remove( pm )\r\n \r\nor \r\n \r\n >>> rm.remove( [ p for p in rm.person[:] if p.name.pyval == 'joe' ] )\r\n \r\nto remove the first person: \r\n \r\n**lxml**:\r\n \r\n >>> p = r.person[0]\r\n >>> r.remove( p )\r\n \r\n**lxml-mate**:\r\n\r\n >>> rm.remove( 0 ) \r\n \r\n \r\ndump to file\r\n------------\r\n\r\n**lxml**:\r\n \r\n >>> f = open( 'person.xml', 'w' )\r\n >>> s = etree.tostring( r )\r\n >>> f.write( s )\r\n >>> f.close()\r\n \r\n**lxml-mate**:\r\n \r\n >>> rm.dump( 'person.xml' )\r\n \r\n \r\nload from file\r\n--------------\r\n\r\n**lxml**:\r\n \r\n >>> r = objectify.XML( 'person.xml' )\r\n \r\n**lxml-mate**:\r\n \r\n >>> rm = ObjectifiedElementProxy( xmlFile = 'person.xml' ) \r\n\r\n\r\ncreate a brand new xml\r\n----------------------\r\n \r\n**lxml**:\r\n \r\n >>> r = objectify.Element('root')\r\n \r\n**lxml-mate**:\r\n \r\n >>> rm = ObjectifiedElementProxy( rootag='root' )\r\n\r\n \r\nElse\r\n----\r\n\r\nto access a tag:\r\n \r\n >>> rm.person[0]\r\n >>> rm[ 'person' ][0]\r\n >>> rm.person\r\n >>> rm.person[ 'name' ]\r\n \r\nto modify a tag's value:\r\n \r\n >>> rm.person.age = 23\r\n \r\nto get a tag's pyval:\r\n \r\n >>> rm.person.age.pyval\r\n\r\nto modify a tag's attrib:\r\n \r\n >>> rm.person[0].attrib['height'] = \"170cm\" \r\n \r\nto modify tag:\r\n \r\n >>> rm.person[-1].tag = 'people'\r\n \r\nto clean empty node ( no attributes & no children ):\r\n \r\n >>> rm.clean()\r\n \r\nYou can use lxml.objectify.ObjectifiedElement's methods directly like this:\r\n \r\n >>> rm.addattr( 'kkk','vvv' )\r\n \r\n\r\n\r\nDependencies\r\n============\r\nlxml https://github.com/lxml/lxml/\r\n\r\n\r\n\r\nInstallion\r\n==========\r\n >>> pip install lxml-mate\r\n\t\r\n\t\r\nChangelog\r\n=========\r\n\r\n0.5.3 (2015-07-20)\r\n------------------\r\n* fix ObjectifiedElementProxy( xmlFileName='...' ) error.\r\n\r\n0.5.2 (2015-07-10)\r\n------------------\r\n* add xpath method.\r\n* improve document and readme.rst.\r\n\r\n0.5.0 (2015-06-29)\r\n------------------\r\n* initial public release.",
"description_content_type": null,
"docs_url": "https://pythonhosted.org/lxml-mate/",
"download_url": "UNKNOWN",
"downloads": {
"last_day": -1,
"last_month": -1,
"last_week": -1
},
"home_page": "https://github.com/david-shu/lxml-mate",
"keywords": "xml lxml",
"license": "MIT",
"maintainer": "",
"maintainer_email": "",
"name": "lxml-mate",
"package_url": "https://pypi.org/project/lxml-mate/",
"platform": "UNKNOWN",
"project_url": "https://pypi.org/project/lxml-mate/",
"project_urls": {
"Download": "UNKNOWN",
"Homepage": "https://github.com/david-shu/lxml-mate"
},
"release_url": "https://pypi.org/project/lxml-mate/0.5.3/",
"requires_dist": null,
"requires_python": null,
"summary": "The simplest Object-XML mapper for Python. Mate for lxml.",
"version": "0.5.3"
},
"last_serial": 1640746,
"releases": {
"0.5.2": [
{
"comment_text": "",
"digests": {
"md5": "794abfc0d64f9b6da11674c3fdba79a5",
"sha256": "9399ce5cba12ceb4b1a8fbccaa10723e21ec585400564d030f8acf518c71f15d"
},
"downloads": -1,
"filename": "lxml-mate-0.5.2.zip",
"has_sig": false,
"md5_digest": "794abfc0d64f9b6da11674c3fdba79a5",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12526,
"upload_time": "2015-07-10T02:55:59",
"url": "https://files.pythonhosted.org/packages/d4/e5/fc5d5a219c29f11168ba24a6bf99ea2c8a358ae2122d634f12210071e7f2/lxml-mate-0.5.2.zip"
}
],
"0.5.3": [
{
"comment_text": "",
"digests": {
"md5": "048a4dde1f83cc5e05f069fda09644e4",
"sha256": "af742a81e3da4512574fa12a017971a63a70b12da3c6e6a9f8f0b75ae8ddfee4"
},
"downloads": -1,
"filename": "lxml-mate-0.5.3.zip",
"has_sig": false,
"md5_digest": "048a4dde1f83cc5e05f069fda09644e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12897,
"upload_time": "2015-07-20T00:33:39",
"url": "https://files.pythonhosted.org/packages/bd/fa/2e13059f1fc2a1089ae1caba0880561c40f3d7f4d95cd57efe970a1bbfa4/lxml-mate-0.5.3.zip"
}
]
},
"urls": [
{
"comment_text": "",
"digests": {
"md5": "048a4dde1f83cc5e05f069fda09644e4",
"sha256": "af742a81e3da4512574fa12a017971a63a70b12da3c6e6a9f8f0b75ae8ddfee4"
},
"downloads": -1,
"filename": "lxml-mate-0.5.3.zip",
"has_sig": false,
"md5_digest": "048a4dde1f83cc5e05f069fda09644e4",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 12897,
"upload_time": "2015-07-20T00:33:39",
"url": "https://files.pythonhosted.org/packages/bd/fa/2e13059f1fc2a1089ae1caba0880561c40f3d7f4d95cd57efe970a1bbfa4/lxml-mate-0.5.3.zip"
}
]
}