简体   繁体   English

获取 xpath 到 xml 的不正确元素。 Python,lxml

[英]Get xpath to incorrect element of xml. Python, lxml

I'm using python to work with xml document, with the help of lxml package.在 lxml package 的帮助下,我使用 python 来处理 xml 文档。 An xsd scheme is used to validate that document. xsd 方案用于验证该文档。 When an error occures, validator raises ParseError with a position of incorrect element.发生错误时,验证器会引发 ParseError 并带有不正确元素的 position。 But what I need is an xpath to that element.但我需要的是该元素的 xpath。 Is there any way to get it?有没有办法得到它?

Assuming the validator give you the position of incorrect element (for example: 8), you could try to access it with the following XPath expression:假设验证器为您提供了错误元素的 position(例如:8),您可以尝试使用以下 XPath 表达式访问它:

(//*)[position()=8]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM