当前位置: 首页>>代码示例>>Python>>正文


Python minidom.Node方法代码示例

本文整理汇总了Python中xml.dom.minidom.Node方法的典型用法代码示例。如果您正苦于以下问题:Python minidom.Node方法的具体用法?Python minidom.Node怎么用?Python minidom.Node使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在xml.dom.minidom的用法示例。


在下文中一共展示了minidom.Node方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,name,world=None):
        self.world = world
        self.actions = set()
        self.legal = {}
        self.omega = True
#        self.O = True
        self.models = {}
        self.modelList = {}
        self.x = None
        self.y = None
        self.color = None
        if isinstance(name,Document):
            self.parse(name.documentElement)
        elif isinstance(name,Node):
            self.parse(name)
        else:
            self.name = name
        self.parallel = False
        self.epsilon = 1e-6 
开发者ID:pynadath,项目名称:psychsim,代码行数:21,代码来源:agent.py

示例2: _xml_node_to_dict

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def _xml_node_to_dict(node):
    assert isinstance(node, minidom.Node)
    if len(node.childNodes) == 0:
        # there's no data for this leaf node
        value = None
    elif len(node.childNodes) == 1 and node.childNodes[0].nodeType == node.TEXT_NODE:
        # there is data for this leaf node
        value = node.childNodes[0].nodeValue
    else:
        # this is an internal node
        value = {}
        for child in node.childNodes:
            d = _xml_node_to_dict(child)
            child_name = child.nodeName
            assert list(d.keys()) == [child_name]
            if child_name not in value:
                # copy the value into the dict
                value[child_name] = d[child_name]
            elif type(value[child_name]) == list:
                # add to the existing list
                value[child_name].append(d[child_name])
            else:
                # create a new list
                value[child_name] = [value[child_name], d[child_name]]
    return {node.nodeName: value} 
开发者ID:XLSForm,项目名称:pyxform,代码行数:27,代码来源:xform_instance_parser.py

示例3: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,arg={}):
        self._keysIn = None
        self._keysOut = None
        if isinstance(arg,Node):
            try:
                super().__init__()
            except TypeError:
                super(KeyedMatrix,self).__init__()
            self.parse(arg)
        else:
            try:
                super().__init__(arg)
            except TypeError:
                super(KeyedMatrix,self).__init__(arg)
            self._string = None 
开发者ID:pynadath,项目名称:psychsim,代码行数:17,代码来源:matrix.py

示例4: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,leaf=None):
        self._string = None
        self._keysIn = None
        self._keysOut = None
        if isinstance(leaf,Node):
            self.parse(leaf)
        else:
            self.makeLeaf(leaf) 
开发者ID:pynadath,项目名称:psychsim,代码行数:10,代码来源:tree.py

示例5: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,planes,threshold=None,comparison=None):
        """
        :warning: if S{planes} is a list, then S{threshold} and S{comparison} are ignored
        """
        if isinstance(planes,Node):
            self.parse(planes)
        elif isinstance(planes,KeyedVector):
            # Only a single branch passed
            if threshold is None:
                threshold = self.DEFAULT_THRESHOLD
            if comparison is None:
                comparison = self.DEFAULT_COMPARISON
            self.planes = [(planes,threshold,comparison)]
        else:
            self.planes = []
            for plane in planes:
                if len(plane) == 3:
                    self.planes.append(plane)
                elif len(plane) == 2:
                    self.planes.append((plane[0],plane[1],self.DEFAULT_COMPARISON))
                elif len(plane) == 1:
                    self.planes.append((plane[0],self.DEFAULT_THRESHOLD,self.DEFAULT_COMPARISON))
                else:
                    raise ValueError('Empty plane passed into constructor')
        self._string = None
        self._keys = None
        self.isConjunction = True 
开发者ID:pynadath,项目名称:psychsim,代码行数:29,代码来源:plane.py

示例6: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,arg={}):
        collections.MutableMapping.__init__(self)
        self._data = {}
        self._string = None
        if isinstance(arg,Node):
            self.parse(arg)
        else:
            self._data.update(arg) 
开发者ID:pynadath,项目名称:psychsim,代码行数:10,代码来源:vector.py

示例7: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,args=None):
        self.x = {}
        self.y = {}
        self.color = {}
        if isinstance(args,Node):
            self.parse(args) 
开发者ID:pynadath,项目名称:psychsim,代码行数:8,代码来源:diagram.py

示例8: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,arg={},description=None):
        if isinstance(arg,Node):
            dict.__init__(self)
            self.parse(arg)
        if isinstance(arg,str):
            values = arg.split('-')
            dict.__init__(self,{self.special[i]: values[i] for i in range(len(values))})
        else:
            dict.__init__(self,arg)
        self._string = None
        self.description = description 
开发者ID:pynadath,项目名称:psychsim,代码行数:13,代码来源:action.py

示例9: get_meta_from_xml

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def get_meta_from_xml(xml_str, meta_name):
    xml = clean_and_parse_xml(xml_str)
    children = xml.childNodes
    # children ideally contains a single element
    # that is the parent of all survey elements
    if children.length == 0:
        raise ValueError(_("XML string must have a survey element."))
    survey_node = children[0]
    meta_tags = [n for n in survey_node.childNodes if
                 n.nodeType == Node.ELEMENT_NODE and
                 (n.tagName.lower() == "meta" or
                     n.tagName.lower() == "orx:meta")]
    if len(meta_tags) == 0:
        return None

    # get the requested tag
    meta_tag = meta_tags[0]
    uuid_tags = [n for n in meta_tag.childNodes if
                 n.nodeType == Node.ELEMENT_NODE and
                 (n.tagName.lower() == meta_name.lower() or
                  n.tagName.lower() == u'orx:%s' % meta_name.lower())]
    if len(uuid_tags) == 0:
        return None

    uuid_tag = uuid_tags[0]
    return uuid_tag.firstChild.nodeValue.strip() if uuid_tag.firstChild\
        else None 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:29,代码来源:xform_instance_parser.py

示例10: save_list

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def save_list(self, doc, items, prop_node):
        items_node = doc.createElement('items')
        prop_node.appendChild(items_node)
        for item in items:
            item_node = doc.createElement('item')
            items_node.appendChild(item_node)
            if isinstance(item, Node):
                item_node.appendChild(item)
            else:
                text_node = doc.createTextNode(item)
                item_node.appendChild(text_node) 
开发者ID:VirtueSecurity,项目名称:aws-extender,代码行数:13,代码来源:xmlmanager.py

示例11: marshal_object

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def marshal_object(self, obj, doc=None):
        if not doc:
            doc = self.new_doc()
        if not doc:
            doc = self.doc
        obj_node = doc.createElement('object')

        if obj.id:
            obj_node.setAttribute('id', obj.id)

        obj_node.setAttribute('class', '%s.%s' % (obj.__class__.__module__,
                                                  obj.__class__.__name__))
        root = doc.documentElement
        root.appendChild(obj_node)
        for property in obj.properties(hidden=False):
            prop_node = doc.createElement('property')
            prop_node.setAttribute('name', property.name)
            prop_node.setAttribute('type', property.type_name)
            value = property.get_value_for_datastore(obj)
            if value is not None:
                value = self.encode_value(property, value)
                if isinstance(value, list):
                    self.save_list(doc, value, prop_node)
                elif isinstance(value, Node):
                    prop_node.appendChild(value)
                else:
                    text_node = doc.createTextNode(six.text_type(value).encode("ascii", "ignore"))
                    prop_node.appendChild(text_node)
            obj_node.appendChild(prop_node)

        return doc 
开发者ID:VirtueSecurity,项目名称:aws-extender,代码行数:33,代码来源:xmlmanager.py

示例12: marshal_object

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def marshal_object(self, obj, doc=None):
        if not doc:
            doc = self.new_doc()
        if not doc:
            doc = self.doc
        obj_node = doc.createElement('object')

        if obj.id:
            obj_node.setAttribute('id', obj.id)

        obj_node.setAttribute('class', '%s.%s' % (obj.__class__.__module__,
                                                  obj.__class__.__name__))
        root = doc.documentElement
        root.appendChild(obj_node)
        for property in obj.properties(hidden=False):
            prop_node = doc.createElement('property')
            prop_node.setAttribute('name', property.name)
            prop_node.setAttribute('type', property.type_name)
            value = property.get_value_for_datastore(obj)
            if value is not None:
                value = self.encode_value(property, value)
                if isinstance(value, list):
                    self.save_list(doc, value, prop_node)
                elif isinstance(value, Node):
                    prop_node.appendChild(value)
                else:
                    text_node = doc.createTextNode(unicode(value).encode("ascii", "ignore"))
                    prop_node.appendChild(text_node)
            obj_node.appendChild(prop_node)

        return doc 
开发者ID:canvasnetworks,项目名称:canvas,代码行数:33,代码来源:xmlmanager.py

示例13: CreateNode

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def CreateNode(name):
    node = minidom.Node()
    node.nodeName = name
    node._attrs = {}
    node.childNodes = []
    return node 
开发者ID:thiagoralves,项目名称:OpenPLC_Editor,代码行数:8,代码来源:xmlclass.py

示例14: __init__

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def __init__(self,xml=None,single=False):
        """
        :param xml: Initialization argument, either an XML Element, or a filename
        :type xml: Node or str
        :param single: If True, then there is no uncertainty about the state of this world (default is False)
        :type single: bool
        """
        self.agents = {}

        # State feature information
        if single:
            self.state = KeyedVector({CONSTANT: 1.})
        else:
            self.state = VectorDistributionSet()
        self.variables = {}
        self.locals = {}
        self.symbols = {}
        self.symbolList = []
        self.termination = []
        self.relations = {}

        # Turn order state info
        self.maxTurn = None
        self.turnSubstate = None
        self.turnKeys = set()

        # Action effect information
        self.dynamics = {}
        self.conditionalDynamics = {}
        self.newDynamics = {True: []}
        self.dependency = psychsim.graph.DependencyGraph(self)

        self.history = []

        self.diagram = None
        self.extras = {}

        if isinstance(xml,Node):
            self.parse(xml)
        elif isinstance(xml,str):
            if xml[-4:] == '.xml':
                # Uncompressed
                f = open(xml,'r')
            else:
                if xml[-4:] != '.psy':
                    xml = '%s.psy' % (xml)
                f = bz2.BZ2File(xml,'r')
            doc = parseString(f.read())
            f.close()
            self.parse(doc.documentElement)
        self.parallel = False 
开发者ID:pynadath,项目名称:psychsim,代码行数:53,代码来源:world.py

示例15: _xml_node_to_dict

# 需要导入模块: from xml.dom import minidom [as 别名]
# 或者: from xml.dom.minidom import Node [as 别名]
def _xml_node_to_dict(node, repeats=[]):
    assert isinstance(node, minidom.Node)
    if len(node.childNodes) == 0:
        # there's no data for this leaf node
        return None
    elif len(node.childNodes) == 1 and \
            node.childNodes[0].nodeType == node.TEXT_NODE:
        # there is data for this leaf node
        return {node.nodeName: node.childNodes[0].nodeValue}
    else:
        # this is an internal node
        value = {}
        for child in node.childNodes:

            # handle CDATA text section
            if child.nodeType == child.CDATA_SECTION_NODE:
                return {child.parentNode.nodeName: child.nodeValue}

            d = _xml_node_to_dict(child, repeats)
            if d is None:
                continue
            child_name = child.nodeName
            child_xpath = xpath_from_xml_node(child)
            assert d.keys() == [child_name]
            node_type = dict
            # check if name is in list of repeats and make it a list if so
            if child_xpath in repeats:
                node_type = list

            if node_type == dict:
                if child_name not in value:
                    value[child_name] = d[child_name]
                else:
                    # Duplicate Ona solution when repeating group is not present,
                    # but some nodes are still making references to it.
                    # Ref: https://github.com/onaio/onadata/commit/7d65fd30348b2f9c6ed6379c7bf79a523cc5750d
                    node_value = value[child_name]
                    # 1. check if the node values is a list
                    if not isinstance(node_value, list):
                        # if not a list, create one
                        value[child_name] = [node_value]
                    # 2. parse the node
                    d = _xml_node_to_dict(child, repeats)
                    # 3. aggregate
                    value[child_name].append(d[child_name])
            else:
                if child_name not in value:
                    value[child_name] = [d[child_name]]
                else:
                    value[child_name].append(d[child_name])
        if value == {}:
            return None
        else:
            return {node.nodeName: value} 
开发者ID:awemulya,项目名称:kobo-predict,代码行数:56,代码来源:xform_instance_parser.py


注:本文中的xml.dom.minidom.Node方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。