Home | History | Annotate | Download | only in etree

Lines Matching refs:element

61     "Element", "ElementTree",
78 # The <b>Element</b> type is a flexible container object, designed to
82 # Each element has a number of properties associated with it:
85 # this element represents (the element type, in other words).</li>
92 # To create an element instance, use the {@link #Element} constructor
95 # The {@link #ElementTree} class can be used to wrap an element
106 def find(self, element, tag, namespaces=None):
107 for elem in element:
111 def findtext(self, element, tag, default=None, namespaces=None):
112 elem = self.find(element, tag)
116 def iterfind(self, element, tag, namespaces=None):
118 for elem in element.iter(tag[3:]):
120 for elem in element:
123 def findall(self, element, tag, namespaces=None):
124 return list(self.iterfind(element, tag, namespaces))
144 # Checks if an object appears to be a valid element object.
146 # @param An element instance.
147 # @return A true value if this is an element object.
150 def iselement(element):
153 return isinstance(element, Element) or hasattr(element, "tag")
156 # Element class. This class defines the Element interface, and
159 # The element name, attribute names, and attribute values can be
163 # @param tag The element name.
164 # @param attrib An optional dictionary, containing element attributes.
166 # @see Element
171 class Element(object):
175 # (Attribute) Element tag.
180 # (Attribute) Element attribute dictionary. Where possible, use
181 # {@link #Element.get},
182 # {@link #Element.set},
183 # {@link #Element.keys}, and
184 # {@link #Element.items} to access
185 # element attributes.
198 # (Attribute) Text after this element's end tag, but before the
199 # next sibling element's start tag. This is either a string or
215 return "<Element %s at 0x%x>" % (repr(self.tag), id(self))
218 # Creates a new element object of the same type as this element.
220 # @param tag Element tag.
221 # @param attrib Element attributes, given as a dictionary.
222 # @return A new element instance.
228 # (Experimental) Copies the current element. This creates a
231 # @return A new element instance.
242 # full elements; to check if there's any content in an element, you
263 # @exception IndexError If the given element does not exist.
272 # @param element The new element value.
273 # @exception IndexError If the given element does not exist.
275 def __setitem__(self, index, element):
277 # for elt in element:
280 # assert iselement(element)
281 self._children[index] = element
287 # @exception IndexError If the given element does not exist.
293 # Adds a subelement to the end of this element. In document order,
294 # the new element will appear after the last existing subelement (or
296 # the end tag for this element.
298 # @param element The element to add.
300 def append(self, element):
301 # assert iselement(element)
302 self._children.append(element)
311 # for element in elements:
312 # assert iselement(element)
316 # Inserts a subelement at the given position in this element.
320 def insert(self, index, element):
321 # assert iselement(element)
322 self._children.insert(index, element)
330 # element.
332 # @param element What element to remove.
333 # @exception ValueError If a matching element could not be found.
335 def remove(self, element):
336 # assert iselement(element)
337 self._children.remove(element)
344 # @defreturn list of Element instances
357 # @param path What element to look for.
359 # @return The first matching element, or None if no element was found.
360 # @defreturn Element or None
368 # @param path What element to look for.
369 # @param default What to return if the element was not found.
371 # @return The text content of the first matching element, or the
372 # default value no element was found. Note that if the element
383 # @param path What element to look for.
387 # @defreturn list of Element instances
395 # @param path What element to look for.
399 # @defreturn a generated sequence of Element instances
405 # Resets an element. This function removes all subelements, clears
415 # Gets an element attribute. Equivalent to <b>attrib.get</b>, but
428 # Sets an element attribute. Equivalent to <b>attrib[key] = value</b>,
442 # @return A list of element attribute names.
449 # Gets element attributes, as a sequence. The attributes are
459 # Creates a tree iterator. The iterator loops over this element
491 # Creates a text iterator. The iterator loops over this element
511 _Element = _ElementInterface = Element
514 # Subelement factory. This function creates an element instance, and
515 # appends it to an existing element.
517 # The element name, attribute names, and attribute values can be
520 # @param parent The parent element.
522 # @param attrib An optional dictionary, containing element attributes.
524 # @return An element instance.
525 # @defreturn Element
530 element = parent.makeelement(tag, attrib)
531 parent.append(element)
532 return element
535 # Comment element factory. This factory function creates a special
536 # element that will be serialized as an XML comment by the standard
543 # @return An element instance, representing a comment.
544 # @defreturn Element
547 element = Element(Comment)
548 element.text = text
549 return element
552 # PI element factory. This factory function creates a special element
558 # @return An element instance, representing a PI.
559 # @defreturn Element
562 element = Element(ProcessingInstruction)
563 element.text = target
565 element.text = element.text + " " + text
566 return element
597 # ElementTree wrapper class. This class represents an entire element
601 # @param element Optional root element.
607 def __init__(self, element=None, file=None):
608 # assert element is None or iselement(element)
609 self._root = element # first node
614 # Gets the root element for this tree.
616 # @return An element instance.
617 # @defreturn Element
623 # Replaces the root element for this tree. This discards the
625 # element. Use with care.
627 # @param element An element instance.
629 def _setroot(self, element):
630 # assert iselement(element)
631 self._root = element
634 # Loads an external XML document into this element tree.
640 # @return The document root element.
641 # @defreturn Element
664 # Creates a tree iterator for the root element. The iterator loops
689 # @param path What element to look for.
691 # @return The first matching element, or None if no element was found.
692 # @defreturn Element or None
709 # @param path What element to look for.
710 # @param default What to return if the element was not found.
712 # @return The text content of the first matching element, or the
713 # default value no element was found. Note that if the element
733 # @param path What element to look for.
737 # @defreturn list of Element instances
755 # @param path What element to look for.
759 # @defreturn a generated sequence of Element instances
774 # Writes the element tree to a file, as XML.
860 qnames[qname] = encode(tag) # default element
1110 # Generates a string representation of an XML element, including all
1113 # @param element An Element instance.
1120 def tostring(element, encoding=None, method=None):
1126 ElementTree(element).write(file, encoding, method=method)
1130 # Generates a string representation of an XML element, including all
1133 # @param element An Element instance.
1141 def tostringlist(element, encoding=None, method=None):
1147 ElementTree(element).write(file, encoding, method=method)
1152 # Writes an element tree or element structure to sys.stdout. This
1158 # @param elem An element tree or an individual element.
1173 # Parses an XML document into an element tree.
1186 # Parses an XML document into an element tree incrementally, and reports
1305 # @return An Element instance.
1306 # @defreturn Element
1316 # a dictionary which maps from element id:s to elements.
1321 # @return A tuple containing an Element instance and a dictionary.
1322 # @defreturn (Element, dictionary)
1341 # @return An Element instance.
1342 # @defreturn Element
1352 # @return An Element instance.
1353 # @defreturn Element
1366 # Generic element structure builder. This builder converts a sequence
1368 # #TreeBuilder.end} method calls to a well-formed element structure.
1370 # You can use this class to build an element structure using a custom XML
1373 # @param element_factory Optional element factory. This factory
1374 # is called to create new Element instances, as necessary.
1380 self._elem = [] # element stack
1381 self._last = None # last element
1384 element_factory = Element
1389 # element.
1391 # @return An Element instance.
1392 # @defreturn Element
1396 assert self._last is not None, "missing toplevel element"
1412 # Adds text to the current element.
1421 # Opens a new element.
1423 # @param tag The element name.
1424 # @param attrib A dictionary containing element attributes.
1425 # @return The opened element.
1426 # @defreturn Element
1438 # Closes the current element.
1440 # @param tag The element name.
1441 # @return The closed element.
1442 Element
1456 # Element structure builder for XML source data, based on the
1664 # @return An element structure.
1665 # @defreturn Element