.. _moduleXmlnode:

music21.xmlnode
===============

.. WARNING: DO NOT EDIT THIS FILE: AUTOMATICALLY GENERATED. Edit the .py file directly

.. module:: music21.xmlnode

An object base-class for creating and editing specialized XML structures
as object representations.  Used by the musicxml converter, obviously, but
also by environment.py.




.. function:: fixed_writexml(writer, indent='', addindent='', newl='')


XMLNode
-------



.. class:: XMLNode()





    >>> from music21 import *
    >>> a = xmlnode.XMLNode()
    >>> a.set('charData', 'test')



    **XMLNode** **attributes**

        Attributes without Documentation: `charData`

    **XMLNode** **properties**

        .. attribute:: tag

            No documentation.


    **XMLNode** **methods**

        .. method:: get(name)


            Get a data attribute from this XMLNode. If available in the
            attribute dictionary, return this first.

            If available as an object attribute, return this second.



        .. method:: getNewDoc()

            No documentation.


        .. method:: hasAttrs()




            >>> from music21 import *
            >>> a = xmlnode.XMLNode()
            >>> a.hasAttrs()
            False
            >>> a = musicxml.Pitch()
            >>> a.hasAttrs()
            False
            >>> a = musicxml.Beam()
            >>> a.hasAttrs()
            True



        .. method:: loadAttrs(attrs)

            Given a SAX attrs object, load all atributes that are named within this object's _attr dictionary.



        .. method:: merge(other, favorSelf=True, returnDeepcopy=True)

            Given another similar or commonly used XMLNode object, combine
            all attributes and return a new object.



            >>> from music21 import *
            >>> a = xmlnode.XMLNode()
            >>> a.set('charData', 'green')
            ⁠ 
            >>> b = xmlnode.XMLNode()
            >>> c = b.merge(a)
            >>> c.get('charData')
            'green'



        .. method:: set(name, value)

            Set an attribute, using either the name of the attribute, a name that can be converter, or a direct attribute on the object.



        .. method:: setDefaults()

            provide defaults for all necessary attributes at this level



        .. method:: toxml(doc=None, parent=None, stringOut=False)

            Provides XML output as either a text string or as DOM node.
            This method can be called recursively to build up nodes on a DOM tree.
            This method will assume that if an self.charData attribute has been
            defined this is a text element for this node. Attributes, sub
            entities, and sub nodes are obtained via subclassed method calls.



        .. method:: xmlStr()

            Shortcut method to provide quick xml out.



XMLNodeList
-----------

Inherits from: :class:`~music21.xmlnode.XMLNode`

.. class:: XMLNodeList()


    To understand what a XMLNodeList is, we need to first see that Nodes are simply
    xml-like containers. Though many xml-like containers store just character
    data, like::

        <fifths>0</fifths>

    Other xml-like containers are really more like lists, not storing character
    data but other xml-like containers in order, like::

        <attributes>
        <divisions>1</divisions>
        <key>
           <fifths>0</fifths>
           <mode>major</mode>
        </key>
        <time symbol="common">
           <beats>4</beats>
           <beat-type>4</beat-type>
        </time>
        <clef>
           <sign>G</sign>
           <line>2</line>
        </clef>
        </attributes>

    In these cases, its much easier to have an xml-like container that is list like.
    That way they can be iterated over or appended to.  Thus, NodeLists, which are
    nodes that give us list-like functionality for the cases where we need them.



    **XMLNodeList** **attributes**

        Attributes without Documentation: `componentList`

        Attributes inherited from :class:`~music21.xmlnode.XMLNode`: :attr:`~music21.xmlnode.XMLNode.charData`

    **XMLNodeList** **properties**

        Properties inherited from :class:`~music21.xmlnode.XMLNode`: :attr:`~music21.xmlnode.XMLNode.tag`

    **XMLNodeList** **methods**

        .. method:: append(item)

            No documentation.


        Methods inherited from :class:`~music21.xmlnode.XMLNode`: :meth:`~music21.xmlnode.XMLNode.get`, :meth:`~music21.xmlnode.XMLNode.getNewDoc`, :meth:`~music21.xmlnode.XMLNode.hasAttrs`, :meth:`~music21.xmlnode.XMLNode.loadAttrs`, :meth:`~music21.xmlnode.XMLNode.merge`, :meth:`~music21.xmlnode.XMLNode.set`, :meth:`~music21.xmlnode.XMLNode.setDefaults`, :meth:`~music21.xmlnode.XMLNode.toxml`, :meth:`~music21.xmlnode.XMLNode.xmlStr`


