Home | Trees | Indices | Help |
---|
|
object --+ | ObjectifiedElementProxy
Proxy class for objectify.ObjectifiedElement instance which can be created by objectify.Element() or SubElement() or XML() or fromstring().
main purpose is to intercept AttributeException when access a non-existent tag.
The following keywords are used as methods or attributes' names.
pyval : returns the python value carried by leaf tag. read-only.
text : returns leaf tag's text content. read-only.
obj : returns ObjectifiedElement object referenced by this class instance. read-only.
tag : returns tag names. can be modified by . way such as *.tag='newTagName'. readable and writable.
attrib : returns tag attributes dict. readable and writeable.
parent : returns parent node. read-only.
children : returns all children's list. read-only.
len : returns the number of children.
insert : insert a child node at the specified position.
remove : remove a child node at the specified position.
index : returns the position of the specified object.
swap : swap two nodes' position.
create a brand new xml:
>>> p = ObjectifiedElmentProxy( rootag='Person' ) >>> p.name = 'peter' >>> p.age = 13 >>> print( p ) <Person> <name>peter</name> <age>13</age> </Person>
create from xml string:
>>> p = ObjectifiedElementProxy( xmlStr="<Person><name>peter</name><age>13</age></Person>" ) >>> print( p ) <Person> <name>peter</name> <age>13</age> </Person>
multiple levels examples:
>>> r = ObjectifiedElementProxy() >>> r.person.name = 'jack' >>> r.person.age = 10 >>> print( r ) <root> <person> <name>jack</name> <age>10</age> </person> </root>
to insert child like '<person><name>peter</name><age>13</age></person>':
>>> r.insert( 'person' )('name','peter')('age',13)
>>> p = r('person').person[-1] >>> p.name = 'david' >>> p.age = 16 >>> print( r ) <root> <person> <name>jack</name> <age>10</age> </person> <person> <name>peter</name> <age>13</age> </person> <person> <name>david</name> <age>16</age> </person> </root>
>>> print( r.station[1].name.pyval ) peter
xml attrib names and tag names are case insensitive.
Nodes with text attribute are called leaf nodes. Theoretically, leaf nodes should not have children, but not required.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
Inherited from |
|
|||
children | |||
parent | |||
root | |||
obj | |||
pyval | |||
Inherited from |
|
initialize from ObjectifiedElement or xml file or xml string or create a brand new. Arguments
|
Insert a new child node. insert a new child node to the end. Arguments
ReturnsObjectifiedElementProxy instance See Alsoinsert note the difference between the two methods' return values. Examples>>> p=ObjectifiedElementProxy( rootag='Person' ) >>> p( 'name', pyval='jack' )('age', pyval=13 ) >>> print( p ) <Person> <name py:pytype="str">jack</name> <age py:pytype="int">13</age> </Person> |
|
|
Insert a new child node. insert a new child node at the specified position. Arguments
|
swap two child nodes' position. Arguments
|
remove the child node. Arguments
|
return the position of o. Arguments
Returnsint |
find elements list in accordance with path. Arguments --------- path : str please refer to lxml.objectify.ObjectifiedElement.xpath. Returns ------- list a list of ObjectifiedElementProxy instance. Xpath grammer review -------------------- ========== =========== expression description ========== =========== nodename to select all children of the node name / select from root node. // select from current node . select the current code. .. select the parent node of the current node. @ select attrib. [] condition text() tag text * arbitrary node ========== ============ |
To determine whether a null node. no text no attribs no children. |
|
save xml to file. Arguments
|
|
children
|
parent
|
root
|
obj
|
pyval
|
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Fri Jul 10 11:04:45 2015 | http://epydoc.sourceforge.net |