Python xpth中的单引号和双引号转义序列
我在使用XPATH从xml文件读取以下元素时遇到以下错误 XML元素。Python xpth中的单引号和双引号转义序列,python,xml,xpath,elementtree,quotes,Python,Xml,Xpath,Elementtree,Quotes,我在使用XPATH从xml文件读取以下元素时遇到以下错误 XML元素。 <test id="1234" name="PPP_TEST-"WWS"_API's"> value="PPP_TEST-"WWS"_API's" Xpath=".//test[@name=\"" + value + "\"]/status" 轨迹路
<test id="1234" name="PPP_TEST-"WWS"_API's">
value="PPP_TEST-"WWS"_API's"
Xpath=".//test[@name=\"" + value + "\"]/status"
轨迹路径:
Traceback (most recent call last):
File "LocalpathPython38-32\lib\xml\etree\ElementPath.py", line 354, in iterfind
selector = _cache[cache_key]
KeyError: ('.//test[@name="PPP_TEST-"WWS"_API\'s"]/status',)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Localpath\LParser.py", line 58, in <module>
print(run.get_testcase_execution_status("test", 'name'))
File "Localpath\Parser.py", line 21, in get_testcase_execution_status
for status in LogParser.root.findall(".//test[@name=\"" + testcaseNames[i] + "\"]/status"):
File "Localpath\Python38-32\lib\xml\etree\ElementPath.py", line 395, in findall
return list(iterfind(elem, path, namespaces))
File "Localpath\Python38-32\lib\xml\etree\ElementPath.py", line 368, in iterfind
selector.append(ops[token[0]](next, token))
File "Localpath\Python38-32\lib\xml\etree\ElementPath.py", line 321, in prepare_predicate
raise SyntaxError("invalid predicate")
SyntaxError: invalid predicate
回溯(最近一次呼叫最后一次):
iterfind中的第354行文件“LocalpathPython38-32\lib\xml\etree\ElementPath.py”
选择器=\u缓存[缓存\u键]
KeyError:('.//test[@name=“PPP\u test-“WWS”\u API的“]/status',)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“Localpath\LParser.py”,第58行,在
打印(run.get\u testcase\u execution\u status(“test”,“name”))
文件“Localpath\Parser.py”,第21行,处于get\u testcase\u execution\u状态
对于LogParser.root.findall(“.//test[@name=\”“+testcaseNames[i]+“\”]/status”)中的状态:
文件“Localpath\Python38-32\lib\xml\etree\ElementPath.py”,第395行,findall中
返回列表(iterfind(元素、路径、名称空间))
文件“Localpath\Python38-32\lib\xml\etree\ElementPath.py”,第368行,在iterfind中
selector.append(ops[token[0]](下一步,token))
文件“Localpath\Python38-32\lib\xml\etree\ElementPath.py”,第321行,在prepare\u谓词中
引发语法错误(“无效谓词”)
SyntaxError:无效谓词
请您帮助我如何对单引号和双引号应用转义序列。您能够解析xml吗?它为此抛出了一个错误
xml格式不正确。如果属性值分隔符是双引号,则属性值中不能有任何双引号。是。我可以解析名称。您如何解析此xml?你能解释一下吗?请分享xml和能够解析它的代码。