用Python脚本进行xml查询 module\u rm=“资源管理器” def get_数据_名称(自身、路径): dataClass=“logicalRouterInterface” dataProp=“dn” msg=”“” """ xml\u response=self.send\u xml(消息,模块) root=ET.fromstring(xml\u响应) dataint=root.findall(“./outConfigs/”+dataClass) 打印“匹配数据接口的编号”,len(dataint)

用Python脚本进行xml查询 module\u rm=“资源管理器” def get_数据_名称(自身、路径): dataClass=“logicalRouterInterface” dataProp=“dn” msg=”“” """ xml\u response=self.send\u xml(消息,模块) root=ET.fromstring(xml\u响应) dataint=root.findall(“./outConfigs/”+dataClass) 打印“匹配数据接口的编号”,len(dataint),python,xml,search,scripting,contains,Python,Xml,Search,Scripting,Contains,变量路径包含值“org root/org tcs/org-edgerouter-csr1”,但数据类即“logicalRouterInterface”,数据属性即“dn”确切值是“org root/org tcs/org-edgerouter-csr1/router-intf-data2”,但我不知道确切值,我只知道值的一部分。 此查询不返回匹配的接口,因为它需要精确的值。请帮助修改此项,以便根据此部分值进行搜索 我注意到您的输入XML(msg)缺少cookie=的引号。修复后可能会工作: mo

变量路径包含值“org root/org tcs/org-edgerouter-csr1”,但数据类即“logicalRouterInterface”,数据属性即“dn”确切值是“org root/org tcs/org-edgerouter-csr1/router-intf-data2”,但我不知道确切值,我只知道值的一部分。
此查询不返回匹配的接口,因为它需要精确的值。请帮助修改此项,以便根据此部分值进行搜索

我注意到您的输入XML(
msg
)缺少
cookie=
的引号。修复后可能会工作:

module_rm = "resource-mgr"
def get_data_name(self, path):
    dataClass = "logicalRouterInterface"
    dataProp = "dn"
    msg = """<?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <configResolveClass cookie="""+ self.authenticate()+ """ inHierarchical="false" classId=""" + "\"" + dataClass + "\"" + """>
    <inFilter>
            <eq class=""" + "\"" + dataClass + "\"" + """
            property=""" + "\"" + dataProp + "\"" + """
            value=""" + "\"" + path + "\"" + """
        />
    </inFilter>
    </configResolveClass>"""
    xml_response = self.send_xml(msg, module_rm)

    root = ET.fromstring( xml_response )
    dataint = root.findall("./outConfigs/" + dataClass)
    print "Number of matching datainterface ", len(dataint)


代码正在运行。但在value属性中,我传递的是部分字符串“org root/org tcs/org-edgerouter-csr1”,但其完整值是“org root/org tcs/org-edgerouter-csr1/router-intf-data2”。因此,它返回0匹配。如果我传递了完整的值,那么它返回正确的值。但我不知道它的全部价值。你所拥有的是特定于应用程序的,我不知道它有什么帮助。我很抱歉。
    <configResolveClass cookie=\""""+ self.authenticate()+ """\" inHierarchical="false" classId=""" + "\"" + dataClass + "\"" + """>